home *** CD-ROM | disk | FTP | other *** search
- /* Copyright (c) 1995 by Oracle Corporation. All Rights Reserved.
- *
- * sysfp.h - Oracle MOOSE Host File System I/O
- *
- * NOTE: In a threaded environment, this interface will be thread-safe
- * and well-behaved (non-blocking to the process) if possible.
- */
-
- #ifndef SYSFP_ORACLE
- #define SYSFP_ORACLE
-
- #ifndef ORALIMITS
- #include <limits.h>
- #define ORALIMITS
- #endif
- #ifndef ORASTDIO
- #include <stdio.h>
- #define ORASTDIO
- #endif
- #ifndef SYSX_ORACLE
- #include <sysx.h>
- #endif
- #ifndef YS_ORACLE
- #include <ys.h>
- #endif
-
- /*
- * sysfp - file handle
- */
- typedef struct sysfp sysfp;
-
- /*
- * sysfpOpen - open a file
- *
- * DESCRIPTION
- * sysfpOpen() opens file fn and associates a stream with it. If the open
- * succeeds, the routine returns a pointer to be used to identify this
- * stream. type is a character string having one of the values defined for
- * the ANSI fopen() operation. kind describes the kind of the file, and may
- * be used by the routine as supplementary to determine how to open the file.
- * Acceptable values for kind are
- *
- * SYSFPKIND_BINARY - binary data file
- * SYSFPKIND_TEXT - text file
- *
- * All other values (possibly null) will be treated as SYSFPKIND_BINARY.
- *
- * If an error occurs, a null pointer is returned, and system-specific
- * error text is returned.
- */
- sysfp *sysfpOpen(CONST char *fn, CONST char *type, CONST char *kind,
- CONST char **errtxt);
-
- /*
- * sysfpClose - close a file
- *
- * DESCRIPTION
- * sysfpClose() closes a file stream previously opened with sysfpOpen().
- */
- void sysfpClose(sysfp *fp);
-
- /*
- * sysfpEof - returns true if at eof
- *
- * DESCRIPTION
- * sysfpEof() returns true if EOF has been detected on this stream;
- * false otherwise.
- */
- boolean sysfpEof(sysfp *fp);
-
- /*
- * sysfpSeek, sysfpTell - random file access
- *
- * DESCRIPTION
- * sysfpSeek() seeks to a byte offset position in the file. The offset
- * is expressed in bytes measured from the beginning of the file. Note
- * that on text files especially, arithmetic on offsets may not always
- * be meaningful. If the offset specifies a position past the end of
- * the file, the results are unpredictable (e.g. the file may be extended,
- * an error may be reported, etc.). sysfpSeek() returns TRUE if the seek
- * succeeded; FALSE otherwise.
- *
- * sysfpTell() reports the current byte offset in the file. The result
- * is written to offset. Note that values returned from sysfpTell() are
- * the only ones that may absolutely reliably be passed to sysfpSeek().
- */
- boolean sysfpSeek(sysfp *fp, CONST sysb8 *offset);
- void sysfpTell(sysfp *fp, sysb8 *offset);
-
- /*
- * sysfpRead, sysfpWrite - file input & output
- *
- * DESCRIPTION
- * sysfpRead() reads at most len bytes from the file stream fp into the
- * buffer buf. The number of bytes actually read is returned. It may be
- * less than len (possibly zero) if there is no more data in the file
- * (or the file is not opened for reading).
- *
- * sysfpWrite() writes the buffer buf of len bytes to the file stream fp.
- * The number of bytes actually written is returned. It may be less than
- * len if an error occurred during writing.
- */
- size_t sysfpRead(sysfp *fp, dvoid *buf, size_t len);
- size_t sysfpWrite(sysfp *fp, dvoid *buf, size_t len);
-
- /*
- * sysfpFlush - flush output
- *
- * DESCRIPTION
- * sysfpFlush() flushes buffered output without closing the stream.
- * It returns TRUE on success; FALSE otherwise.
- */
- boolean sysfpFlush(sysfp *fp);
-
- /*
- * sysfpPrint - print to file
- *
- * DESCRIPTION
- * sysfpPrint() writes to the open file designated by fp. The fmt and
- * subsequent arguments are interpreted as for printf(). The file must
- * have been opened with appropriate access. If there is an error,
- * sysfpPrint() returns FALSE.
- */
- boolean sysfpPrint(sysfp *fp, CONST char *fmt, ...);
-
- /*
- * sysfpGets - get a line
- *
- * SYNOPSIS
- * char *sysfpGets(sysfp *fp, char *buf, size_t maximum);
- *
- * DESCRIPTION
- * sysfpGets() reads characters from the open file designated by fp into
- * the array pointed to by buf, until maximum-1 characters are read, or
- * a newline character is read and transferred to s, or an end-of-file
- * condition is encountered. The string is then terminated with a null
- * character. If an end-of-file is encountered and no characters have
- * been read, a null pointer is returned; otherwise, buf is returned.
- */
- #define sysfpGets(fp, b, m) fgets((b), (m), (FILE *) (fp))
-
- /*
- * sysfpGetc - get a character
- *
- * SYNOPSIS
- * boolean sysfpGetc(sysfp *fp, sword *ch);
- *
- * DESCRIPTION
- * sysfpGetc() gets a character from the open file designated by fp. If
- * the end of the file is reached, sysfpGetc() returns TRUE; otherwise,
- * *ch is set to the character that was read and the routine returns FALSE.
- */
- #define sysfpGetc(fp, ch) ((*ch) = (sword) getc((FILE *) (fp)), (*ch) == EOF)
-
- /*
- * sysfpAccess - tests for access to a file
- *
- * DESCRIPTION
- * sysfpAccess() tests the filename to see if it can be opened with the
- * access specified in type. type is a character string taking on the
- * same set of values as for sysfpOpen().
- */
- boolean sysfpAccess(CONST char *fn, CONST char *type);
-
- /*
- * sysfpIsDir - tests for a directory
- *
- * DESCRIPTION
- * sysfpIsDir() tests the filename to see if it denotes a directory
- * and returns TRUE if it does; FALSE otherwise. (FALSE may indicate
- * an access error).
- */
- boolean sysfpIsDir(CONST char *fn);
-
- /*
- * sysfpGetDir - get directory
- *
- * DESCRIPTION
- * sysfpGetDir() retrieves the contents of a directory. fn must be the
- * name of a directory suitable for reading. sysfpGetDir() should return
- * a list where each element in the list is an allocated string containing
- * the name of a file in the directory (that is, the element vaue should be
- * castable to char *). The list may be freed by the caller using
- *
- * ysLstDestroy(lst, ysmFGlbFree);
- *
- * If there is an error (or the routine is not implemented on the platform),
- * a null pointer is returned. Errors include invalid filenames, access
- * violations, and memory exhaustion.
- */
- yslst *sysfpGetDir(CONST char *fn);
-
-
- /*
- * sysfpSize - return the length of a file
- *
- * DESCRIPTION
- * fn is the name of a file whose length in bytes is determined. If
- * no error occurs, sysfpSize() writes the result to sz and returns
- * null. Otherwise, a pointer to error text explaining the error is
- * returned.
- */
- CONST char *sysfpSize(CONST char *fn, sysb8 *sz);
-
- /*
- * sysfpLast - return last modification time of a file
- *
- * DESCRIPTION
- * fn is the name of a file whose last modification time is to be determined.
- * If no error occurs, sysfpLast() writes the result to mtime and returns
- * null. Otherwise, a pointer to error text explaining the error is returned.
- * The modification time value is seconds since the epoch, the same epoch as
- * used by systmGetClock().
- */
- CONST char *sysfpLast(CONST char *fn, sysb8 *mtime);
-
- /*
- * sysfpRemove - remove a file
- *
- * DESCRIPTION
- * sysfpRemove() removes a file named by fn. On success, null is returned.
- * Otherwise, a system-specific error message is returned.
- */
- CONST char *sysfpRemove(CONST char *fn);
-
- /*
- * sysfpRename - rename a file
- *
- * DESCRIPTION
- * sysfpRename() renames a file named by from to a file named by to. On
- * success, null is returned. Otherwise, a system-specific error message
- * is returned. The system should attempt to ensure that if the rename
- * fails, the original file remains intact under the original name.
- */
- CONST char *sysfpRename(CONST char *from, CONST char *to);
-
- /*
- * sysfpForm - construct a filename
- *
- * DESCRIPTION
- * sysfpForm() constructs a full filename (including path and suffix) from
- * its constituent parts and writes the full name to result, a buffer which
- * must be a minimum of SYSFP_MAX_PATHLEN bytes long.
- *
- * The filename is constructed as follows:
- * + if sfx is non-null, it is appended to the base (but only if the
- * basename does not already have a suffix present);
- * + if path is null or base is an absolute pathname (e.g. begins with
- * a "/" in Unix), path is ignored; otherwise, path is prepended to
- * the base
- *
- * The result is a single filename that fully denotes the path, the filename,
- * and the suffix as appropriate for the host file system. This result is
- * written to result.
- */
- #define SYSFP_MAX_PATHLEN MAX_PATH
-
- void sysfpForm(char *result, CONST char *path, CONST char *base,
- CONST char *sfx);
-
- /*
- * sysfpExtractPath, sysfpExtractFile, sysfpExtractBase, sysfpExtractSuffix
- * - extract components
- *
- * DESCRIPTION
- * sysfpExtractPath() extracts a pathname from a full filename and writes
- * it to path. path must be a minimum of SYSFP_MAX_PATHLEN bytes long. If
- * the filename does not contain any path information, a path that denotes
- * the current directory is returned.
- *
- * sysfpExtractFile() extracts the base filename from a full filename. This
- * is the filename with the path stripped. It is like sysfpExtractBase()
- * except that it will not strip a suffix.
- *
- * sysfpExtractBase() extracts the basename from a full filename, stripping
- * both a path (if any) and suffix (if any).
- *
- * sysfpExtractSuffix() extracts the suffix from a full filename, stripping
- * both a path (if any) and basename. If there is no suffix, a zero-length
- * string is returned.
- */
- void sysfpExtractPath(char *path, CONST char *fn);
- void sysfpExtractFile(char *file, CONST char *fn);
- void sysfpExtractBase(char *base, CONST char *fn);
- void sysfpExtractSuffix(char *sfx, CONST char *fn);
-
-
- /*
- * sysfpTemp - construct a temporary filename
- *
- * DESCRIPTION
- * sysfpTemp() constructs a temporary filename (including path and suffix).
- * The platform will use any trick necessary to ensure that the name generated
- * is relatively unique (this means that if you call this routine 50000 times,
- * it may generate some duplicates, but not after 100 times, certainly.)
- * The resulting name is written to result, a buffer which must be a minimum
- * of SYSFP_MAX_PATHLEN bytes long.
- *
- * If path is not null, it is used as a the pathname where the file should
- * be located. If kind is a recognized kind of file, it will endeavor to
- * do anything necessary when constructing the filename to meet the
- * requirements implied by that kind.
- */
- void sysfpTemp(char *result, CONST char *path, CONST char *sfx);
-
- /*
- * sysfpGetCwd - get current working directory
- *
- * DESCRIPTION
- * sysfpGetCwd() gets the current working directory and writes it to result,
- * a buffer which must be a minimum of SYSFP_MAX_PATHLEN bytes long. On
- * success, null is returned. Otherwise, a system-specific error message is
- * returned and result is not changed.
- */
- CONST char *sysfpGetCwd(char *result);
-
- /*
- * sysfpExtractPath, sysfpExtractFile, sysfpExtractBase, sysfpExtractKind
- * - extract components
- *
- * DESCRIPTION
- * sysfpExtractPath() extracts a pathname from a full filename and writes
- * it to path. path must be a minimum of SYSFP_MAX_PATHLEN bytes long. If
- * the filename does not contain any path information, a path that denotes
- * the current directory is returned.
- *
- * sysfpExtractFile() extracts the base filename from a full filename. This
- * is the filename with the path stripped. It is like sysfpExtractBase()
- * except that it will not strip a suffix.
- *
- * sysfpExtractBase() extracts the basename from a full filename, stripping
- * both a path (if any) and suffix (if any).
- *
- * sysfpExtractKind() extracts the kind from a full filename, returning
- * one of the SYSFPKIND values listed above, depending on the suffix and
- * the name of the file.
- */
- void sysfpExtractPath(char *path, CONST char *fn);
- void sysfpExtractFile(char *file, CONST char *fn);
- void sysfpExtractBase(char *base, CONST char *fn);
- sword sysfpExtractKind(CONST char *fn);
-
- /*
- * Kind Definitions
- */
- #define SYSFPKIND_BINARY (char *) 0
- externref CONST_DATA char SYSFPKIND_TEXT[];
-
- /*
- * The following kinds are obsolete.
- */
- #define SYSFPKIND_NONE (char *) 0
- #define SYSFPKIND_OTHER (char *) 0
- #define SYSFPKIND_CHEADER "h"
- #define SYSFPKIND_CSOURCE "c"
-
- #endif /* SYSFP_ORACLE */
-