home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
rtsi.com
/
2014.01.www.rtsi.com.tar
/
www.rtsi.com
/
OS9
/
OSK
/
TELECOM
/
OS9_Unix.lzh
/
RSHSRC
/
_open.c
next >
Wrap
Text File
|
1992-09-30
|
2KB
|
59 lines
/* _open() --- UNIX three argument open function
ip Sept 92 ... derived from os9lib and gnutar "port" versions
*/
#include <strings.h>
#include <sys/fcntl.h>
#define ERROR -1
#define NULL 0
int _open(name,oflag,mode )
char *name;
int oflag, mode;
{
int path;
char *cp, *getenv();
if (strcmp(name, "/dev/null") == NULL)
name = "/nil";
else
if (strncmp(name, "/dev/tty", 8) == 0 && (cp = getenv("PORT")) != NULL)
name = cp;
if ( oflag == 0 ) /* Unix numerical argument perhaps */
oflag = O_RDONLY;
if (oflag & O_WRONLY) {
if (oflag & O_CREAT)
if (oflag & O_EXCL) {
if (mode&0xf00) return(_errmsg(-1,
"_open.c suspect Unix numerical mode argument to open()"));
return (create(name, oflag & O_RDWR, mode));
} else
return(creat(name, oflag & O_RDWR));
else {
path = open(name, oflag & O_RDWR);
/* however Unix open doesn't stop access to directories, so .. */
if(path <0) path=open(name, (oflag & O_RDWR) | S_IFDIR);
if ( path >= 0 && oflag & O_APPEND )
if (lseek(path, 0, 2) < 0) /* to EOF */
return ERROR;
return(path);
}
}
if ( oflag & O_RDONLY ) {
path = open(name, S_IREAD);
/* however Unix open doesn't stop access to directories, so .. */
if(path <0) path=open(name, S_IREAD | S_IFDIR);
if ( path >= 0 && oflag & O_APPEND )
if (lseek(path, 2, 0) < 0 ) /* to EOF */
return ERROR;
return(path);
}
_errmsg(0,"_open.c: unknown oflag code 0x%x in open()",oflag) ;
return ERROR;
}