Files and Folders

These routines assist your object in opening and saving files, as well as locating the user’s files in the Max search path. More...

Data Structures

struct  t_fileinfo
 Information about a file. More...
 
struct  t_path
 The path data structure. More...
 
struct  t_pathlink
 The pathlink data structure. More...
 

Macros

#define MAX_PATH_CHARS
 The size you should use when allocating strings for full paths.
 
#define MAX_FILENAME_CHARS
 The size you should use when allocating strings for filenames. More...
 

Typedefs

typedef t_filestruct * t_filehandle
 A t_filehandle is a cross-platform way of referring to an open file. More...
 

Enumerations

enum  e_max_path_styles {
  PATH_STYLE_MAX, PATH_STYLE_NATIVE, PATH_STYLE_COLON, PATH_STYLE_SLASH,
  PATH_STYLE_NATIVE_WIN
}
 Constants that determine the output of path_nameconform(). More...
 
enum  e_max_path_types {
  PATH_TYPE_IGNORE, PATH_TYPE_ABSOLUTE, PATH_TYPE_RELATIVE, PATH_TYPE_BOOT,
  PATH_TYPE_C74, PATH_TYPE_PATH, PATH_TYPE_DESKTOP, PATH_TYPE_TILDE,
  PATH_TYPE_TEMPFOLDER, PATH_TYPE_MAXDB
}
 Constants that determine the output of path_nameconform(). More...
 
enum  e_max_fileinfo_flags { PATH_FILEINFO_ALIAS, PATH_FILEINFO_FOLDER, PATH_FILEINFO_PACKAGE }
 Flags used to represent properties of a file in a t_fileinfo struct. More...
 
enum  e_max_path_folder_flags { PATH_REPORTPACKAGEASFOLDER, PATH_FOLDER_SNIFF, PATH_NOALIASRESOLUTION }
 Flags used by functions such as path_foldernextfile() and path_openfolder(). More...
 
enum  e_max_openfile_permissions { PATH_READ_PERM, PATH_WRITE_PERM, PATH_RW_PERM }
 Permissions or mode with which to open a file. More...
 
enum  t_sysfile_pos_mode { SYSFILE_ATMARK, SYSFILE_FROMSTART, SYSFILE_FROMLEOF, SYSFILE_FROMMARK }
 Modes used by sysfile_setpos() More...
 
enum  t_sysfile_text_flags {
  TEXT_LB_NATIVE, TEXT_LB_MAC, TEXT_LB_PC, TEXT_LB_UNIX ,
  TEXT_ENCODING_USE_FILE, TEXT_NULL_TERMINATE
}
 Flags used reading and writing text files. More...
 

Functions

short path_getapppath (void)
 Retrieve the Path ID of the Max application. More...
 
short locatefile (C74_CONST char *name, short *outvol, short *binflag)
 Find a Max document by name in the search path. More...
 
short locatefiletype (C74_CONST char *name, short *outvol, t_fourcc filetype, t_fourcc creator)
 Find a Max document by name in the search path. More...
 
short locatefile_extended (char *name, short *outvol, t_fourcc *outtype, C74_CONST t_fourcc *filetypelist, short numtypes)
 Find a file by name. More...
 
short path_resolvefile (char *name, C74_CONST short path, short *outpath)
 Resolve a Path ID plus a (possibly extended) file name into a path that identifies the file's directory and a filename. More...
 
short path_fileinfo (C74_CONST char *name, C74_CONST short path, t_fileinfo *info)
 Retrive a t_fileinfo structure from a file/path combination. More...
 
short path_topathname (C74_CONST short path, C74_CONST char *file, char *name)
 Create a fully qualified file name from a Path ID/file name combination. More...
 
short path_frompathname (C74_CONST char *name, short *path, char *filename)
 Create a filename and Path ID combination from a fully qualified file name. More...
 
void path_setdefault (short path, short recursive)
 Install a path as the default search path. More...
 
short path_getdefault (void)
 Retrieve the Path ID of the default search path. More...
 
short path_getmoddate (short path, t_ptr_uint *date)
 Determine the modification date of the selected path. More...
 
short path_getfilemoddate (C74_CONST char *filename, C74_CONST short path, t_ptr_uint *date)
 Determine the modification date of the selected file. More...
 
void * path_openfolder (short path)
 Prepare a directory for iteration. More...
 
short path_foldernextfile (void *xx, t_fourcc *filetype, char *name, short descend)
 Get the next file in the directory. More...
 
void path_closefolder (void *x)
 Complete a directory iteration. More...
 
short path_opensysfile (C74_CONST char *name, C74_CONST short path, t_filehandle *ref, short perm)
 Open a file given a filename and Path ID. More...
 
short path_createsysfile (C74_CONST char *name, short path, t_fourcc type, t_filehandle *ref)
 Create a file given a type code, a filename, and a Path ID. More...
 
short path_nameconform (C74_CONST char *src, char *dst, long style, long type)
 Convert a source path string to destination path string using the specified style and type. More...
 
short path_topotentialname (C74_CONST short path, C74_CONST char *file, char *name, short check)
 Create a fully qualified file name from a Path ID/file name combination, regardless of whether or not the file exists on disk. More...
 
t_max_err path_toabsolutesystempath (const short in_path, const char *in_filename, char *out_filepath)
 Translates a Max path+filename combo into a correct POSIX absolute path that can be used to pass to libraries and also handles multiple volumes correctly. More...
 
t_max_err path_absolutepath (t_symbol **returned_path, const t_symbol *s, const t_fourcc *filetypelist, short numtypes)
 Convert a path to an absolutepath as done by the absolutepath object in Max. More...
 
void open_promptset (C74_CONST char *s)
 Use open_promptset() to add a prompt message to the open file dialog displayed by open_dialog(). More...
 
void saveas_promptset (C74_CONST char *s)
 Use saveas_promptset() to add a prompt message to the open file dialog displayed by saveas_dialog() or saveasdialog_extended(). More...
 
void * filewatcher_new (t_object *owner, C74_CONST short path, C74_CONST char *filename)
 Create a new filewatcher. More...
 
void fileusage_addfile (void *w, long flags, C74_CONST char *name, C74_CONST short path)
 Add a file to a collective. More...
 
void fileusage_addpackage (void *w, C74_CONST char *name, t_object *subfoldernames)
 Add a package to a standalone. More...
 
short open_dialog (char *name, short *volptr, t_fourcc *typeptr, t_fourcc *types, short ntypes)
 Present the user with the standard open file dialog. More...
 
short saveas_dialog (char *filename, short *path, short *binptr)
 Present the user with the standard save file dialog. More...
 
short saveasdialog_extended (char *name, short *vol, t_fourcc *type, t_fourcc *typelist, short numtypes)
 Present the user with the standard save file dialog with your own list of file types. More...
 
BEGIN_USING_C_LINKAGE t_max_err sysfile_close (t_filehandle f)
 Close a file opened with sysfile_open(). More...
 
t_max_err sysfile_read (t_filehandle f, t_ptr_size *count, void *bufptr)
 Read a file from disk. More...
 
t_max_err sysfile_readtohandle (t_filehandle f, char ***h)
 Read the contents of a file into a handle. More...
 
t_max_err sysfile_readtoptr (t_filehandle f, char **p)
 Read the contents of a file into a pointer. More...
 
t_max_err sysfile_write (t_filehandle f, t_ptr_size *count, const void *bufptr)
 Write part of a file to disk. More...
 
t_max_err sysfile_seteof (t_filehandle f, t_ptr_size logeof)
 Set the size of a file handle. More...
 
t_max_err sysfile_geteof (t_filehandle f, t_ptr_size *logeof)
 Get the size of a file handle. More...
 
t_max_err sysfile_setpos (t_filehandle f, t_sysfile_pos_mode mode, t_ptr_int offset)
 Set the current file position of a file handle. More...
 
t_max_err sysfile_getpos (t_filehandle f, t_ptr_size *filepos)
 Get the current file position of a file handle. More...
 
t_max_err sysfile_spoolcopy (t_filehandle src, t_filehandle dst, t_ptr_size size)
 Copy the contents of one file handle to another file handle. More...
 
t_max_err sysfile_readtextfile (t_filehandle f, t_handle htext, t_ptr_size maxlen, t_sysfile_text_flags flags)
 Read a text file from disk. More...
 
t_max_err sysfile_writetextfile (t_filehandle f, t_handle htext, t_sysfile_text_flags flags)
 Write a text file to disk. More...
 
t_max_err sysfile_openhandle (char **h, t_sysfile_flags flags, t_filehandle *fh)
 Create a t_filehandle from a pre-existing handle. More...
 
t_max_err sysfile_openptrsize (char *p, t_ptr_size length, t_sysfile_flags flags, t_filehandle *fh)
 Create a t_filehandle from a pre-existing pointer. More...
 

Detailed Description

These routines assist your object in opening and saving files, as well as locating the user’s files in the Max search path.

There have been a significant number of changes to these routines (as well as the addition of many functions), so some history may be useful in understanding their use.

Prior to version 4, Max used a feature of Mac OS 9 called "working directories" to specify files. When you used the locatefile() service routine, you would get back a file name and a volume number. This name (converted to a Pascal string) and the volume number could be passed to FSOpen() to open the located file for reading. The open_dialog() routine worked similarly.

In Mac OSX, working directories are no longer supported. In addition, the use of these "volume" numbers makes it somewhat difficult to port Max file routines to other operating systems, such as Windows XP, that specify files using complete pathnames (i.e., "C:\dir1\dir2\file.pat").

However, it is useful to be able to refer to the path and the name of the file separately. The solution involves the retention of the volume number (now called Path ID), but with a platform- independent wrapper that determines its meaning. There are now calls to locate, open, and choose files using C filename strings and Path IDs, as well as routines to convert between a "native" format for specifying a file (such as a full pathname on Windows or an FSRef on the Macintosh) to the C string and Path ID. As of Max version 5 FSSpecs, long ago deprecated by Apple, are no longer supported.

Now that paths in Max have changed to use the slash style, as opposed to the old Macintosh colon style (see the Max 4.3 documentation for a description of the file path styles), there is one function in particular that you will find useful for converting between the various ways paths can be represented, including operating system native paths. This function is path_nameconform(). Note that for compatibility purposes Path API functions accept paths in any number of styles, but will typically return paths, or modify paths inline to use the newer slash style. In addition to absolute paths, paths relative to the Max Folder, the "Cycling '74" folder and the boot volume are also supported. See the conformpath.help and ext_path.h files for more information on the various styles and types of paths. See the "filebyte" SDK example project for a demonstration of how to use the path functions to convert a Max name and path ref pair to a Windows native path for use with CreateFile().

There are a large number of service routine in the Max 4 kernel that support files, but only a handful will be needed by most external objects. In addition to the descriptions that follow, you should consult the movie, folder and filedate examples included with the SDK.

The Sysfile API

The Sysfile API provides the means of reading and writing files opened by path_createsysfile() and similar. These functions all make use of an opaque structure, t_filehandle. See the path functions path_opensysfile() and path_createsysfile() described earlier in this chapter for more information. The Sysfile API is relatively similar to parts of the old Macintosh File Manager API, and not too different from Standard C library file functions. The "filebyte" example project in the SDK shows how to use these functions to read from a file. It is not safe to mix these routines with other file routines (e.g. don’t use fopen() to open a file and sysfile_close() to close it).

In addition to being able to use these routines to write cross-platform code in your max externals, another advantage of the Sysfile API is that it is able to read files stored in the collective file format on both Windows XP and Mac OSX.

Example: filebyte (notes from the IRCAM workshop)

Paths

t_filehandle

File Names

File Path Names

Collectives and Fileusage

Use the fileusage routines to add files to a collective when a user chooses to build a collective. Your object can respond to a "fileusage" message, which is sent by Max when the collective builder is building a collective using the following:

class_addmethod(c, (method)my_fileusage, "fileusage", A_CANT, 0L);

Where my file usage has the prototype:

void my_fileusage(t_myObject *x, void *w);

Then you can use fileusage_addfile() to add any requisite files to the collective.

Filewatchers

Your object can watch a file or folder and be notified of changes. Use filewatcher_new(), filewatcher_start(), and filewatcher_stop() to implement this functionality. You may wish to use filewatchers sparingly as they can potentially incur computational overhead in the background.

Macro Definition Documentation

#define MAX_FILENAME_CHARS

The size you should use when allocating strings for filenames.

At the time of this writing it supports up to 256 UTF chars

Typedef Documentation

typedef t_filestruct* t_filehandle

A t_filehandle is a cross-platform way of referring to an open file.

It is an opaque structure, meaning you don’t have access to the individual elements of the data structure. You can use a t_filehandle only with the file routines in the Sysfile API. Do not use other platform- specific file functions in conjunction with these functions. The perm parameter can be either READ_PERM, WRITE_PERM, or RW_PERM.

Enumeration Type Documentation

Flags used to represent properties of a file in a t_fileinfo struct.

Enumerator
PATH_FILEINFO_ALIAS 

alias

PATH_FILEINFO_FOLDER 

folder

PATH_FILEINFO_PACKAGE 

package (Mac-only)

Permissions or mode with which to open a file.

Enumerator
PATH_READ_PERM 

Read mode.

PATH_WRITE_PERM 

Write mode.

PATH_RW_PERM 

Read/Write mode.

Flags used by functions such as path_foldernextfile() and path_openfolder().

Enumerator
PATH_REPORTPACKAGEASFOLDER 

if not true, then a Mac OS package will be reported as a file rather than a folder.

PATH_FOLDER_SNIFF 

sniff

PATH_NOALIASRESOLUTION 

no alias resolution

Constants that determine the output of path_nameconform().

See also
e_max_path_types
path_nameconform()
Enumerator
PATH_STYLE_MAX 

use PATH_STYLE_MAX_PLAT

PATH_STYLE_NATIVE 

use PATH_STYLE_NATIVE_PLAT

PATH_STYLE_COLON 

':' sep, "vol:" volume, ":" relative, "^:" boot

PATH_STYLE_SLASH 

'/' sep, "vol:/" volume, "./" relative, "/" boot

PATH_STYLE_NATIVE_WIN 

'\' sep, "vol:\\" volume, ".\\" relative, "\\" boot

Constants that determine the output of path_nameconform().

See also
e_max_path_styles
path_nameconform()
Enumerator
PATH_TYPE_IGNORE 

ignore

PATH_TYPE_ABSOLUTE 

absolute path

PATH_TYPE_RELATIVE 

relative path

PATH_TYPE_BOOT 

boot path

PATH_TYPE_C74 

Cycling '74 folder.

PATH_TYPE_PATH 

path

PATH_TYPE_DESKTOP 

desktop

PATH_TYPE_TILDE 

"home"

PATH_TYPE_TEMPFOLDER 

/tmp

PATH_TYPE_MAXDB 

combi: try PATH_TYPE_C74, PATH_TYPE_TILDE, PATH_TYPE_RELATIVE, PATH_TYPE_ABSOLUTE in that order

Modes used by sysfile_setpos()

Enumerator
SYSFILE_ATMARK 

?

SYSFILE_FROMSTART 

Calculate the file position from the start of the file.

SYSFILE_FROMLEOF 

Calculate the file position from the logical end of the file.

SYSFILE_FROMMARK 

Calculate the file position from the current file position.

Flags used reading and writing text files.

Enumerator
TEXT_LB_NATIVE 

Use the linebreak format native to the current platform.

TEXT_LB_MAC 

Use Macintosh line breaks.

TEXT_LB_PC 

Use Windows line breaks.

TEXT_LB_UNIX 

Use Unix line breaks.

TEXT_ENCODING_USE_FILE 

If this flag is not set then the encoding is forced to UTF8.

TEXT_NULL_TERMINATE 

Terminate memory returned from sysfile_readtextfile() with a NULL character.

Function Documentation

void fileusage_addfile ( void *  w,
long  flags,
C74_CONST char *  name,
C74_CONST short  path 
)

Add a file to a collective.

Parameters
wHandle for the collective builder.
flagsIf flags == 1, copy this file to support folder of an app instead of to the collective in an app.
nameThe name of the file.
pathThe path of the file to add.
void fileusage_addpackage ( void *  w,
C74_CONST char *  name,
t_object subfoldernames 
)

Add a package to a standalone.

Parameters
wHandle for the standalone builder
nameThe name of the package
subfoldernamesA t_atomarray containing symbols, each of which is a foldername in the package to include. Pass NULL to include the entire package contents.
Version
Introduced in Max 7.0.4
void* filewatcher_new ( t_object owner,
C74_CONST short  path,
C74_CONST char *  filename 
)

Create a new filewatcher.

The file will not be actively watched until filewatcher_start() is called. The filewatcher can be freed using object_free().

Parameters
ownerYour object. This object will receive the message "filechanged" when the watcher sees a change in the file or folder.
pathThe path in which the file being watched resides, or the path of the folder being watched.
filenameThe name of the file being watched, or an empty string if you are simply watching the folder specified by path.
Returns
A pointer to the new filewatcher.
Remarks
The "filechanged" method should have the prototype:
1 void myObject_filechanged(t_myObject *x, char *filename, short path);
short locatefile ( C74_CONST char *  name,
short *  outvol,
short *  binflag 
)

Find a Max document by name in the search path.

This routine performs the same function as the routine path_getdefault(). locatefile() searches through the directories specified by the user for Patcher files and tables in the File Preferences dialog as well as the current default path (see path_getdefault) and the directory containing the Max application

Parameters
nameA C string that is the name of the file to look for.
outvolThe Path ID containing the location of the file if it is found.
binflagIf the file found is in binary format (it's of type 'maxb') 1 is returned here; if it's in text format, 0 is returned.
Returns
If a file is found with the name specified by filename, locatefile returns 0, otherwise it returns non-zero.
Remarks
filename and vol can then be passed to binbuf_read to read and open file the file. When using MAXplay, the search path consists of all subdirectories of the directory containing the MAXplay application. locatefile only searches for files of type 'maxb' and 'TEXT.'
See also
locatefile_extended()
short locatefile_extended ( char *  name,
short *  outvol,
t_fourcc outtype,
C74_CONST t_fourcc filetypelist,
short  numtypes 
)

Find a file by name.

If a complete path is not specified, search for the name in the search path. This is the preferred method for file searching since its introduction in Max version 4.

Version
4.0
Parameters
nameThe file name for the search, receives actual filename upon return.
outvolThe Path ID of the file (if found).
outtypeThe file type of the file (if found).
filetypelistThe file type(s) for which you are searching for, or NULL if any type is acceptable.
numtypesThe number of file types in the typelist array (1 if a single entry, 0 if any type is acceptable).
Returns
If a file is found with the name specified by filename, locatefile returns 0, otherwise it returns non-zero.
See also
path_getdefault().
Remarks
The old file search routines locatefile() and locatefiletype() are still supported in Max 4, but the use of a new routine locatefile_extended() is highly recommended. However, locatefile_extended() has an important difference from locatefile() and locatefiletype() that may require some rewriting of your code. It modifies its name parameter in certain cases, while locatefile() and locatefiletype() do not. The two cases where it could modify the incoming filename string are 1) when an alias is specified, the file pointed to by the alias is returned; and 2) when a full path is specified, the output is the filename plus the path number of the folder it's in.

This is important because many people pass the s_name field of a t_symbol to locatefile(). If the name field of a t_symbol were to be modified, the symbol table would be corrupted. To avoid this problem, use strncpy_zero() to copy the contents of a t_symbol to a character string first, as shown below:

1 char filename[MAX_FILENAME_CHARS];
2 strncpy_zero(filename,str->s_name, MAX_FILENAME_CHARS);
3 result = locatefile_extended(filename,&path,&type,typelist,1);
short locatefiletype ( C74_CONST char *  name,
short *  outvol,
t_fourcc  filetype,
t_fourcc  creator 
)

Find a Max document by name in the search path.

This function searches through the same directories as locatefile, but allows you to specify a type and creator of your own.

Parameters
nameA C string that is the name of the file to look for.
outvolThe Path ID containing the location of the file if it is found.
filetypeThe filetype of the file to look for. If you pass 0L, files of all filetypes are considered.
creatorThe creator of the file to look for. If you pass 0L, files with any creator are considered.
Returns
If a file is found with the name specified by filename, locatefile returns 0, otherwise it returns non-zero.
See also
locatefile_extended()
short open_dialog ( char *  name,
short *  volptr,
t_fourcc typeptr,
t_fourcc types,
short  ntypes 
)

Present the user with the standard open file dialog.

This function is convenient wrapper for using Mac OS Navigation Services or Standard File for opening files.

The mapping of extensions to types is configured in the C74:/init/max-fileformats.txt file. The standard types to use for Max files are 'maxb' for old-format binary files, 'TEXT' for text files, and 'JSON' for newer format patchers or other .json files.

Parameters
nameA C-string that will receive the name of the file the user wants to open. The C-string should be allocated with a size of at least MAX_FILENAME_CHARS.
volptrReceives the Path ID of the file the user wants to open.
typeptrThe file type of the file the user wants to open.
typesA list of file types to display. This is not limited to 4 types as in the SFGetFile() trap. Pass NULL to display all types.
ntypesThe number of file types in typelist. Pass 0 to display all types.
Returns
0 if the user clicked Open in the dialog box. If the user cancelled, open_dialog() returns a non-zero value.
See also
saveasdialog_extended()
locatefile_extended()
void open_promptset ( C74_CONST char *  s)

Use open_promptset() to add a prompt message to the open file dialog displayed by open_dialog().

Calling this function before open_dialog() permits a string to displayed in the dialog box instructing the user as to the purpose of the file being opened. It will only apply to the call of open_dialog() that immediately follows open_promptset().

Parameters
sA C-string containing the prompt you wish to display in the dialog box.
Returns
Ignore.
See also
open_dialog()
t_max_err path_absolutepath ( t_symbol **  returned_path,
const t_symbol s,
const t_fourcc filetypelist,
short  numtypes 
)

Convert a path to an absolutepath as done by the absolutepath object in Max.

Parameters
returned_pathAddress to a symbol pointer which will be filled-in upon successful return.
sIncoming (non-absolute) path.
filetypelistThe first of an array of file types to limit the search.
numtypesThe number of entries in the filetypelist parameter.
Returns
A Max error code.
See also
path_topathname()
locatefile_extended()
void path_closefolder ( void *  x)

Complete a directory iteration.

Parameters
xThe "folder state" value originally returned by path_openfolder().
short path_createsysfile ( C74_CONST char *  name,
short  path,
t_fourcc  type,
t_filehandle ref 
)

Create a file given a type code, a filename, and a Path ID.

Parameters
nameThe name of the file to be opened.
pathThe Path ID of the file to be opened.
typeThe file type of the created file.
refA t_filehandle reference to the opened file will be returned in this parameter.
Returns
An error code.
short path_fileinfo ( C74_CONST char *  name,
C74_CONST short  path,
t_fileinfo info 
)

Retrive a t_fileinfo structure from a file/path combination.

Parameters
nameThe file name to be queried.
pathThe Path ID of the file.
infoThe address of a t_fileinfo structure to contain the file information.
Returns
Returns 0 if successful, otherwise it returns an OS-specific error code.
short path_foldernextfile ( void *  xx,
t_fourcc filetype,
char *  name,
short  descend 
)

Get the next file in the directory.

In conjunction with path_openfolder() and path_closefolder(), this routine allows you to iterate through all of the files in a path.

Parameters
xxThe "folder state" value returned by path_openfolder().
filetypeContains the file type of the file type on return.
nameContains the file name of the next file on return.
descendUnused.
Returns
Returns non-zero if successful, and zero when there are no more files.
See also
e_max_path_folder_flags
short path_frompathname ( C74_CONST char *  name,
short *  path,
char *  filename 
)

Create a filename and Path ID combination from a fully qualified file name.

Note that path_frompathname() does not require that the file actually exist. In this way you can use it to convert a full path you may have received as an argument to a file writing message to a form appropriate to provide to a routine such as path_createfile().

Parameters
nameThe extended file path to be converted.
pathContains the Path ID on return.
filenameContains the file name on return.
Returns
Returns 0 if successful, otherwise it returns an OS-specific error code.
short path_getapppath ( void  )

Retrieve the Path ID of the Max application.

Returns
The path id.
short path_getdefault ( void  )

Retrieve the Path ID of the default search path.

Returns
The path id of the default search path.
short path_getfilemoddate ( C74_CONST char *  filename,
C74_CONST short  path,
t_ptr_uint date 
)

Determine the modification date of the selected file.

Parameters
filenameThe name of the file to query.
pathThe Path ID of the file.
dateThe last modification date of the file upon return.
Returns
An error code.
short path_getmoddate ( short  path,
t_ptr_uint date 
)

Determine the modification date of the selected path.

Parameters
pathThe Path ID of the directory to check.
dateThe last modification date of the directory.
Returns
An error code.
short path_nameconform ( C74_CONST char *  src,
char *  dst,
long  style,
long  type 
)

Convert a source path string to destination path string using the specified style and type.

Parameters
srcA pointer to source character string to be converted.
dstA pointer to destination character string.
styleThe destination filepath style, as defined in e_max_path_styles
typeThe destination filepath type, as defined in e_max_path_types
Returns
An error code.
See also
MAX_PATH_CHARS
void* path_openfolder ( short  path)

Prepare a directory for iteration.

Parameters
pathThe directory Path ID to open.
Returns
The return value of this routine is an internal "folder state" structure used for further folder manipulation. It should be saved and used for calls to path_foldernextfile() and path_closefolder(). If the folder cannot be found or accessed, path_openfolder() returns 0.
short path_opensysfile ( C74_CONST char *  name,
C74_CONST short  path,
t_filehandle ref,
short  perm 
)

Open a file given a filename and Path ID.

Parameters
nameThe name of the file to be opened.
pathThe Path ID of the file to be opened.
refA t_filehandle reference to the opened file will be returned in this parameter.
permThe permission for the opened file as defined in e_max_openfile_permissions.
Returns
An error code.
short path_resolvefile ( char *  name,
C74_CONST short  path,
short *  outpath 
)

Resolve a Path ID plus a (possibly extended) file name into a path that identifies the file's directory and a filename.

This routine converts a name and Path ID to a standard form in which the name has no path information and does not refer to an aliased file.

Parameters
nameA file name (which may be fully or partially qualified), will contain the file name on return.
pathThe Path ID to be resolved.
outpathThe Path ID of the returned file name.
Returns
Returns 0 if successful.
void path_setdefault ( short  path,
short  recursive 
)

Install a path as the default search path.

The default path is searched before the Max search path. For instance, when loading a patcher from a directory outside the search path, the patcher's directory is searched for files before the search path. path_setdefault() allows you to set a path as the default.

Parameters
pathThe path to use as the search path. If path is already part of the Max Search path, it will not be added (since, by default, it will be searched during file searches).
recursiveIf non-zero, all subdirectories will be installed in the default search list. Be very careful with the use of the recursive argument. It has the capacity to slow down file searches dramatically as the list of folders is being built. Max itself never creates a hierarchical default search path.
t_max_err path_toabsolutesystempath ( const short  in_path,
const char *  in_filename,
char *  out_filepath 
)

Translates a Max path+filename combo into a correct POSIX absolute path that can be used to pass to libraries and also handles multiple volumes correctly.

Parameters
in_pathThe Max path reference
in_filenameThe name of the file in that path.
out_filepathA string that is MAX_PATH_CHARS in length, which will receive the formatted absolute path upon return.
Returns
Returns 0 if successful.
See also
path_topotentialname()
path_nameconform()
1 // example for getting a windows-formatted path for a folder path:
2 path_toabsolutesystempath(pathid, "", filestring);
3 path_nameconform(filestring, sNativeQualifiedPathname, PATH_STYLE_NATIVE, PATH_TYPE_PATH);
short path_topathname ( C74_CONST short  path,
C74_CONST char *  file,
char *  name 
)

Create a fully qualified file name from a Path ID/file name combination.

Unlike path_topotentialname(), this routine will only convert a pathname pair to a valid path string if the path exists.

Parameters
pathThe path to be used.
fileThe file name to be used.
nameLoaded with the fully extended file name on return.
Returns
Returns 0 if successful, otherwise it returns an OS-specific error code.
short path_topotentialname ( C74_CONST short  path,
C74_CONST char *  file,
char *  name,
short  check 
)

Create a fully qualified file name from a Path ID/file name combination, regardless of whether or not the file exists on disk.

Parameters
pathThe path to be used.
fileThe file name to be used.
nameLoaded with the fully extended file name on return.
checkFlag to check if a file with the given path exists.
Returns
Returns 0 if successful, otherwise it returns an OS-specific error code.
See also
path_topathname()
short saveas_dialog ( char *  filename,
short *  path,
short *  binptr 
)

Present the user with the standard save file dialog.

The mapping of extensions to types is configured in the C74:/init/max-fileformats.txt file. The standard types to use for Max files are 'maxb' for old-format binary files, 'TEXT' for text files, and 'JSON' for newer format patchers or other .json files.

Parameters
filenameA C-string containing a default name for the file to save. If the user decides to save a file, its name is returned here. The C-string should be allocated with a size of at least MAX_FILENAME_CHARS.
pathIf the user decides to save the file, the Path ID of the location chosen is returned here.
binptrPass NULL for this parameter. This parameter was used in Max 4 to allow the choice of saving binary or text format patchers.
Returns
0 if the user choose to save the file. If the user cancelled, returns a non-zero value.
See also
open_dialog()
saveasdialog_extended()
locatefile_extended()
void saveas_promptset ( C74_CONST char *  s)

Use saveas_promptset() to add a prompt message to the open file dialog displayed by saveas_dialog() or saveasdialog_extended().

Calling this function before saveasdialog_extended() permits a string to displayed in the dialog box instructing the user as to the purpose of the file being opened. It will only apply to the call of saveasdialog_extended() that immediately follows saveas_promptset().

Parameters
sA C-string containing the prompt you wish to display in the dialog box.
Returns
Ignore.
See also
open_dialog()
short saveasdialog_extended ( char *  name,
short *  vol,
t_fourcc type,
t_fourcc typelist,
short  numtypes 
)

Present the user with the standard save file dialog with your own list of file types.

saveasdialog_extended() is similar to saveas_dialog(), but allows the additional feature of specifying a list of possible types. These will be displayed in a pop-up menu.

File types found in the typelist argument that match known Max types will be displayed with descriptive text. Unmatched types will simply display the type name (for example, "foXx" is not a standard type so it would be shown in the pop-up menu as foXx)

Known file types include:

  • TEXT: text file
  • maxb: Max binary patcher
  • maxc: Max collective
  • Midi: MIDI file
  • Sd2f: Sound Designer II audio file
  • NxTS: NeXT/Sun audio file
  • WAVE: WAVE audio file.
  • AIFF: AIFF audio file
  • mP3f: Max preference file
  • PICT: PICT graphic file
  • MooV: Quicktime movie file
  • aPcs: VST plug-in
  • AFxP: VST effect patch data file
  • AFxB: VST effect bank data file
  • DATA: Raw data audio file
  • ULAW: NeXT/Sun audio file
Parameters
nameA C-string containing a default name for the file to save. If the user decides to save a file, its name is returned here. The C-string should be allocated with a size of at least MAX_FILENAME_CHARS.
volIf the user decides to save the file, the Path ID of the location chosen is returned here.
typeReturns the type of file chosen by the user.
typelistThe list of types provided to the user.
numtypesThe number of file types in typelist.
Returns
0 if the user choose to save the file. If the user cancelled, returns a non-zero value.
See also
open_dialog()
locatefile_extended()

Close a file opened with sysfile_open().

This function is similar to FSClose() or fclose(). It should be used instead of system-specific file closing routines in order to make max external code that will compile cross-platform.

Parameters
fThe t_filehandle structure of the file the user wants to close.
Returns
An error code.
t_max_err sysfile_geteof ( t_filehandle  f,
t_ptr_size logeof 
)

Get the size of a file handle.

This function is similar to and should be used instead of GetEOF(). The function gets the size of file handle in bytes, and places it in �“logeof?.

Parameters
fThe file's t_filehandle structure.
logeofThe file size in bytes is returned to this value.
Returns
An error code.
t_max_err sysfile_getpos ( t_filehandle  f,
t_ptr_size filepos 
)

Get the current file position of a file handle.

This function is similar to and should be used instead of GetFPos(). The function gets the current file position of file handle in bytes, and places it in "filepos".

Parameters
fThe file's t_filehandle structure.
fileposThe address of a variable to hold the current file position of file handle in bytes.
Returns
An error code.
t_max_err sysfile_openhandle ( char **  h,
t_sysfile_flags  flags,
t_filehandle fh 
)

Create a t_filehandle from a pre-existing handle.

Parameters
hA handle for some data, data is *not* copied and *not* freed on file close.
flagsPass 0 (additional flags are private).
fhThe address of a t_filehandle which will be allocated.
Returns
An error code.
t_max_err sysfile_openptrsize ( char *  p,
t_ptr_size  length,
t_sysfile_flags  flags,
t_filehandle fh 
)

Create a t_filehandle from a pre-existing pointer.

Parameters
pA pointer to some data. Data is *not* copied and *not* freed on file close.
lengthThe size of p.
flagsPass 0 (additional flags are private).
fhThe address of a t_filehandle which will be allocated.
Returns
An error code.
t_max_err sysfile_read ( t_filehandle  f,
t_ptr_size count,
void *  bufptr 
)

Read a file from disk.

This function is similar to FSRead() or fread(). It should be used instead of these functions (or other system-specific file reading routines) in order to make max external code that will compile cross-platform. It reads "count" bytes from file handle at current file position into "bufptr". The byte count actually read is set in "count", and the file position is updated by the actual byte count read.

Parameters
fThe t_filehandle structure of the file the user wants to open.
countPointer to the number of bytes that will be read from the file at the current file position. The byte count actually read is returned to this value.
bufptrPointer to the buffer that the data will be read into.
Returns
An error code.

Referenced by jit_bin_read_chunk_info(), jit_bin_read_header(), and jit_bin_read_matrix().

t_max_err sysfile_readtextfile ( t_filehandle  f,
t_handle  htext,
t_ptr_size  maxlen,
t_sysfile_text_flags  flags 
)

Read a text file from disk.

This function reads up to the maximum number of bytes given by maxlen from file handle at current file position into the htext handle, performing linebreak translation if set in flags.

Parameters
fThe t_filehandle structure of the text file the user wants to open.
htextHandle that the data will be read into.
maxlenThe maximum length in bytes to be read into the handle. Passing the value 0L indicates no maximum (i.e. read the entire file).
flagsFlags to set linebreak translation as defined in t_sysfile_text_flags.
Returns
An error code.
t_max_err sysfile_readtohandle ( t_filehandle  f,
char ***  h 
)

Read the contents of a file into a handle.

Parameters
fThe open t_filehandle structure to read into the handle.
hThe address of a handle into which the file will be read.
Returns
An error code.
Remarks
You should free the pointer, when you are done with it, using sysmem_freehandle().
t_max_err sysfile_readtoptr ( t_filehandle  f,
char **  p 
)

Read the contents of a file into a pointer.

Parameters
fThe open t_filehandle structure to read into the handle.
pThe address of a pointer into which the file will be read.
Returns
An error code.
Remarks
You should free the pointer, when you are done with it, using sysmem_freeptr().
t_max_err sysfile_seteof ( t_filehandle  f,
t_ptr_size  logeof 
)

Set the size of a file handle.

This function is similar to and should be used instead of SetEOF(). The function sets the size of file handle in bytes, specified by �“logeof?.

Parameters
fThe file's t_filehandle structure.
logeofThe file size in bytes.
Returns
An error code.
t_max_err sysfile_setpos ( t_filehandle  f,
t_sysfile_pos_mode  mode,
t_ptr_int  offset 
)

Set the current file position of a file handle.

This function is similar to and should be used instead of SetFPos(). It is used to set the current file position of file handle to by the given number of offset bytes relative to the mode used, as defined in t_sysfile_pos_mode.

Parameters
fThe file's t_filehandle structure.
modeMode from which the offset will be calculated, as defined in t_sysfile_pos_mode.
offsetThe offset in bytes relative to the mode.
Returns
An error code.

Referenced by jit_bin_read_chunk_info(), jit_bin_read_header(), and jit_bin_write_header().

t_max_err sysfile_spoolcopy ( t_filehandle  src,
t_filehandle  dst,
t_ptr_size  size 
)

Copy the contents of one file handle to another file handle.

Parameters
srcThe file handle from which to copy.
dstThe file handle to which the copy is written.
sizeThe number of bytes to copy. If 0 the size of src will be used.
Returns
An error code.
t_max_err sysfile_write ( t_filehandle  f,
t_ptr_size count,
const void *  bufptr 
)

Write part of a file to disk.

This function is similar to FSWrite() or fwrite(). It should be used instead of these functions (or other system-specific file reading routines) in order to make max external code that will compile cross-platform. The function writes "count" bytes from "bufptr" into file handle at current file position. The byte count actually written is set in "count", and the file position is updated by the actual byte count written.

Parameters
fThe t_filehandle structure of the file to which the user wants to write.
countPointer to the number of bytes that will be written to the file at the current file position. The byte count actually written is returned to this value.
bufptrPointer to the buffer that the data will be read from.
Returns
An error code.

Referenced by jit_bin_write_header(), and jit_bin_write_matrix().

t_max_err sysfile_writetextfile ( t_filehandle  f,
t_handle  htext,
t_sysfile_text_flags  flags 
)

Write a text file to disk.

This function writes a text handle to a text file performing linebreak translation if set in flags.

Parameters
fThe t_filehandle structure of the text file to which the user wants to write.
htextHandle that the data that will be read from.
flagsFlags to set linebreak translation as defined in t_sysfile_text_flags.
Returns
An error code.
  Copyright © 2015, Cycling '74