Function Entry: OPEN
← Prev | ↑ Chapter | Next → | Index | Symbols
Function Entry: OPEN
Name
open
Class
Function
Syntax
(open filename mode [encoding])
Arguments and Values
filename: stringmode: string designating read, write, or appendencoding: optional encoding designator; see File encoding below
Description
Opens a file and returns a file descriptor.
File encoding
The optional third argument is version-qualified: pre-2021 open has
no encoding argument at all. It was introduced by AutoCAD 2021 and is
supported in BricsCAD V21 and higher.
The values the vendors document are:
| value | meaning |
|---|---|
"utf8" |
UTF-8, no byte-order mark |
"utf8-bom" |
UTF-8 preceded by a BOM |
"utf16-bom" |
UTF-16 preceded by a BOM |
With no encoding argument the file is read and written in the host's
system codepage (SYSCODEPAGE).
The reason the list stops there is stated by Bricsys and is worth
repeating, because it is the whole difficulty: "UTF-8 without BOM can
not be distinguished from normal ANSI." There is no byte sequence that
tells the two apart, so a file written as UTF-8 without a mark is
indistinguishable from one written in the host codepage — and on a host
whose codepage is not cp1252 (macOS, where SYSCODEPAGE is
MACROMAN) it is decoded wrongly, silently. This is the mechanism behind
the observed macOS mis-decoding, not a separate bug.
Modes "r", "w" and "a" are text; "rb", "wb" and "ab" are
binary, where no decoding applies and the encoding argument is
meaningless.
Consistency required of any implementation
Whatever the file encoding, a decoded non-ASCII character must satisfy
(= (chr N) <the same character decoded from a file>)
— one canonical internal representation per character, however it
entered the image. BricsCAD's native chr diverges from this today
(see cad-chr-vs-loaded-encoding.issue for the measurements);
clautolisp satisfies it. Stating the rule here is what gives alfe a
contract to honour when it hands sources to a CAD host: transcode to
UTF-8 with a BOM, which is the one form every post-2021 engine reads
unambiguously.
Return Values
Returns a FILE descriptor or nil on failure, depending on host behavior and context.
Side Effects
Creates or opens an external file channel.
Affected By
- path-resolution rules
- trusted-path rules
- encoding support
Exceptional Situations
Errors are reported for invalid paths, modes, or inaccessible files.
Examples
(open "foo.txt" "r")
Compatibility
- older Autodesk forms lacked explicit encoding: the argument is an AutoCAD 2021 feature, mirrored by BricsCAD from V21
- BricsCAD documents richer text mode handling
Source Notes
- Bricsys, BricsCAD Developer Reference V25,
open— https://developer.bricsys.com/bricscad/help/en_US/V25/DevRef/source/open.htm (the encoding values and the "cannot be distinguished from normal ANSI" statement are verbatim from that page). - The AutoCAD 2021 Unicode changes are the same feature under
LISPSYS; the two vendors agree on the argument.
Notes
clautolisp should decouple path semantics from native OS via environment profiles.
In clautolisp, open resolves a relative name through the support search
path (an existing file is found on the path; a new name falls back to the
current directory, so write semantics are unchanged). That current
directory is the process working directory at launch — matching
BricsCAD/AutoCAD, which resolve a relative name against the current directory
— and user code may query or change it with vl-getcurrentdir /
vl-setcurrentdir. This holds identically whether clautolisp runs standalone
or in-process behind alfe --clautolisp (the in-process backend re-anchors
to the live cwd at start-up; see
issues/closed/cad-open-relative-path-not-resolved-vs-cwd.issue). open is
also gated by the trust model for files whose extension is in the gated
set: at
SECURELOAD 2 an untrusted gated file is blocked (ERRNO + a
:open-untrusted-file error), at 1 it warns and proceeds; ordinary data
files are never gated. Autodesk does not gate open — this is a
clautolisp extension (1.2.18 / 1.2.20). See Normative Rules: Secure File
Loading and Trust Model (this chapter).
Availability
- AutoCAD 2026: documented (per Autodesk reference page).
- BricsCAD V26: presumed compatible (no contradicting page found).
- Status: AutoCAD documented; BricsCAD presumed-both pending Phase 4 verification.
See Also
- BricsCAD V26 extends
openwith encoding selectors of the form"r,ccs=UNICODE","r,ccs=UTF-8","r,ccs=UTF-16LE","w,ccs=UTF-8","w,ccs=UTF-16LE". AutoCAD does not accept these; AutoCAD's Unicode story is governed by theLISPSYSsystem variable instead. - Divergence documented in
vendor-inventory-2026.org§10 item 2.
Source Notes
- [open (AutoLISP), current](https://help.autodesk.com/cloudhelp/2026/PLK/AutoCAD-LT-AutoLISP-Reference/files/GUID-089A323F-21FF-4337-99A9-375758E23BA4.htm)
- [open (AutoLISP), earlier](https://help.autodesk.com/cloudhelp/2015/ENU/AutoCAD-AutoLISP/files/GUID-089A323F-21FF-4337-99A9-375758E23BA4.htm)
- [read + write text files (BricsCAD)](https://developer.bricsys.com/bricscad/help/en_US/V25/DevRef/source/readwritetextfiles.htm)
- Status: documented with version drift.