/*----------------------------------------------------------------------* rtp_wfile_open *----------------------------------------------------------------------*/ int rtp_wfile_open (RTP_HANDLE * fdPtr, const unsigned short * name, unsigned short flag, unsigned short mode) { #if (_WIN32_WINNT) >= 0x0400 long fileHandle; int result; #ifdef RTP_DEBUG /* ----------------------------------- */ /* Clear the error state by setting */ /* to 0. */ /* ----------------------------------- */ SetLastError(0); #endif name = (unsigned short *)_rtp_unicode_name_to_winname ((unsigned short *) name); fileHandle = (long) _wopen (name, _rtp_flag_to_operation(flag), _rtp_mode_to_permission(mode)); if (fileHandle == (-1)) { result = GetLastError(); /* ----------------------------------- */ /* If trying to open a directory or */ /* opening a read only file with */ /* write privilages. This can be */ /* non-fatal if doing an open to */ /* determine the existance of a */ /* directory. */ /* ----------------------------------- */ if (result == ERROR_ACCESS_DENIED) { #ifdef RTP_DEBUG RTP_DEBUG_OUTPUT_STR("rtp_wfile_open: non-fatal error returned "); RTP_DEBUG_OUTPUT_INT(result); RTP_DEBUG_OUTPUT_STR(".\n"); #endif return (-2); } #ifdef RTP_DEBUG RTP_DEBUG_OUTPUT_STR("rtp_wfile_open: error returned "); RTP_DEBUG_OUTPUT_INT(result); RTP_DEBUG_OUTPUT_STR(".\n"); #endif return (-1); } *fdPtr = (RTP_HANDLE) fileHandle; return (0); #endif return (-1); }
/*----------------------------------------------------------------------* rtp_file_open *----------------------------------------------------------------------*/ int rtp_file_open (RTP_HANDLE * fdPtr, const char * name, unsigned short flag, unsigned short mode) { int fileHandle; #ifdef RTP_DEBUG /* ----------------------------------- */ /* Clear the error state by setting */ /* to 0. */ /* ----------------------------------- */ errno = 0; #endif fileHandle = open (name, _rtp_flag_to_operation(flag), _rtp_mode_to_permission(mode)); if (fileHandle == (-1)) { /* ----------------------------------- */ /* If trying to open a directory or */ /* opening a read only file with */ /* write privilages. This can be */ /* non-fatal if doing an open to */ /* determine the existance of a */ /* directory. */ /* ----------------------------------- */ if (errno == EACCES) { #ifdef RTP_DEBUG RTP_DEBUG_OUTPUT_STR("rtp_file_open: non-fatal error returned "); RTP_DEBUG_OUTPUT_INT(errno); RTP_DEBUG_OUTPUT_STR(".\n"); #endif return (-2); } #ifdef RTP_DEBUG RTP_DEBUG_OUTPUT_STR("rtp_file_open: error returned "); RTP_DEBUG_OUTPUT_INT(errno); RTP_DEBUG_OUTPUT_STR(".\n"); #endif return (-1); } /* Ignore RTP_FILE_S_HIDDEN, RTP_FILE_S_SYSTEM, and RTP_FILE_S_ARCHIVE. */ *fdPtr = (RTP_HANDLE) fileHandle; #ifdef RTP_DEBUG RTP_DEBUG_OUTPUT_STR("rtp_file_open: "); RTP_DEBUG_OUTPUT_STR("...success"); RTP_DEBUG_OUTPUT_STR(".\n"); #endif return (0); }
/** @memo Opens a file using the supplied name. @doc Opens a file using the mode settings, and sets the file information. @return 0 if successful, -1 on failure, and -2 if a non-fatal error occurred. */ int rtp_stdio_fopen ( void ** rtpfile, /** A pointer to the address of an RTP_FILE to store the file information. */ const char * fname, /** The name of the file to open. */ const char * mode /** For the mode argument:<br> <pre> | "r" Open a file for reading only RTP_FILE_O_RDONLY | "r+" Open a file for reading and writing RTP_FILE_O_RDWR | "w" Open a file for writing only RTP_FILE_O_WRONLY | Create a file if it does not exist RTP_FILE_O_CREAT | Truncate a file to 0 bytes after opening RTP_FILE_O_TRUNC | "w+" Open a file for reading and writing RTP_FILE_O_RDWR | Create a file if it does not exist RTP_FILE_O_CREAT | Truncate a file to 0 bytes after opening RTP_FILE_O_TRUNC | "a" All writes will be appended to the file RTP_FILE_O_APPEND | Create a file if it does not exist RTP_FILE_O_CREAT | "a+" Open a file for reading and writing RTP_FILE_O_RDWR | All writes will be appended to the file RTP_FILE_O_APPEND | Create a file if it does not exist RTP_FILE_O_CREAT | "b..." b prepended to the mode in the open call | causes the file to be opened in binary mode RTP_FILE_O_BINARY | "t..." t prepended to the mode in the open call | causes the file to be opened in text mode RTP_FILE_O_TEXT | Note: If neither the b or t are prepended, text | mode is the default implementation. </pre> */ ) { RTP_STDIO_FILE * p; int result; result = (-1); p = (RTP_STDIO_FILE *) rtp_malloc ((unsigned int) sizeof (*p), 0); /* SPRZ */ if (p) { rtp_memset(p, 0, sizeof(*p)); p->verify = RTP_FILE_VERIFICATION_VALUE; if ((result = rtp_file_open (&(p->handle), fname, _rtp_mode_to_permission(mode), RTP_FILE_S_IWRITE | RTP_FILE_S_IREAD)) != 0) { /* --------------------------------------- */ /* ERROR: drop the handle block. */ /* --------------------------------------- */ rtp_free ((void *)p); } } *rtpfile = (void *)p; return (result); }
/*----------------------------------------------------------------------* rtp_file_open *----------------------------------------------------------------------*/ int rtp_file_open (RTP_HANDLE * fdPtr, const char * name, unsigned short flag, unsigned short mode) { PCFD fileHandle; int result; #ifdef RTP_DISPLAY_ERROR char error[32]; /* ----------------------------------- */ /* Clear the error state by setting */ /* to 0. */ /* ----------------------------------- */ errno = 0; #endif fileHandle = open (name, _rtp_flag_to_operation(flag), _rtp_mode_to_permission(mode)); if (fileHandle == (PCFD)(-1)) { result = errno; /* ----------------------------------- */ /* If trying to open a directory or */ /* opening a read only file with */ /* write privilages. This can be */ /* non-fatal if doing an open to */ /* determine the existance of a */ /* directory. */ /* ----------------------------------- */ if (result == PEACCES) { #ifdef RTP_DISPLAY_ERROR rtp_term_cputs("rtp_file_open: non-fatal error returned "); rtp_term_puts(rtp_ltoa(result, error, 10)); #endif return (-2); } #ifdef RTP_DISPLAY_ERROR rtp_term_cputs("rtp_file_open: error returned "); rtp_term_puts(rtp_itoa(result, error, 10)); #endif return (-1); } *fdPtr = (RTP_HANDLE) fileHandle; return (0); }
/*----------------------------------------------------------------------* rtp_file_open *----------------------------------------------------------------------*/ int rtp_file_open (RTP_HANDLE * fdPtr, const char * name, unsigned short flag, unsigned short mode) { long fileHandle; #ifdef RTP_DEBUG int result; /* ----------------------------------- */ /* Clear the error state by setting */ /* to 0. */ /* ----------------------------------- */ set_errno (0); #endif name = (char *) _rtp_name_to_nativename((char *) name); fileHandle = (long) vf_open((PFCHAR) name, (word) _rtp_flag_to_operation(flag), (word) _rtp_mode_to_permission(mode)); if (fileHandle == (-1)) { #ifdef RTP_DEBUG result = xn_getlasterror( ); RTP_DEBUG_OUTPUT_STR("rtp_file_open: error returned "); RTP_DEBUG_OUTPUT_INT(result); RTP_DEBUG_OUTPUT_STR(".\n"); #endif return (-1); } *fdPtr = (RTP_HANDLE) fileHandle; return (0); }