| iMatix home page | << | < | > | >> |
SFL Version 2.11 |
#include "sflproc.h" int process_open_io ( const char *filename, char access_type /* r, w, a */ )
Opens a file for i/o and returns a handle ready for passing to process create full(). The filename may be null or empty, in which case this function returns -2, which indicates a null file handle. If there is an error, it returns -1. Otherwise it returns a file handle >= 0.
{ int handle, mode = 0, permissions = 0; if (filename == NULL || *filename == '\0') return (-2); /* Indicates a null handle */ #if (defined (__UNIX__) || defined (__OS2__)) mode = O_NOCTTY; #endif if (access_type == 'r') { mode += O_RDONLY; permissions = 0; } else if (access_type == 'w') { mode += O_WRONLY | O_CREAT | O_TRUNC; permissions = S_IREAD | S_IWRITE; } else if (access_type == 'a') { mode += O_WRONLY | O_CREAT | O_APPEND; permissions = S_IREAD | S_IWRITE; } handle = open (filename, mode, permissions); #if (defined (WIN32)) /* Under Windows, we need to move the file pointer to the end of the * file ourselves, for append files, since for some reason this does * not happen automatically for file handles passed to subprocesses. */ if (access_type == 'a') lseek (handle, 0, SEEK_END); #endif #if (defined (DEBUG)) if (handle < 0) perror ("Error opening redirection stream"); #endif return (handle); }
| << | < | > | >> | Copyright © 1996-2000 iMatix Corporation |