home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
rtsi.com
/
2014.01.www.rtsi.com.tar
/
www.rtsi.com
/
OS9
/
OSK
/
SRC
/
unc.lzh
/
UNC
/
osk.c
< prev
next >
Wrap
C/C++ Source or Header
|
1991-06-10
|
2KB
|
83 lines
#include "osk.h"
char *getenv(), *info_str(), *strdup();
void *malloc();
/* open() ist #umdefiniert nach _open() */
#undef open
int _open(name, oflag, mode)
char *name;
int oflag, mode;
{
int path;
if ((oflag & O_WRONLY) != 0)
{
if (oflag & O_CREAT)
if (oflag & O_EXCL)
return (create(name, oflag & O_RDWR, oflag & O_RDWR));
else
return (creat(name, oflag & O_RDWR));
else
{
path = open(name, S_IWRITE);
if ( path >= 0 && ((oflag & O_APPEND) != 0 ) )
if (lseek(path, 2, 0) < 0) /* ans Fileende gehen */
return(-1);
return(path);
}
}
if ((oflag & O_RDONLY) != 0)
{
path = open(name, S_IREAD);
if ( path >= 0 && ((oflag & O_APPEND) != 0 ) )
if (lseek(path, 2, 0) < 0 ) /* ans Fileende gehen */
return(-1);
return(path);
}
else (perror("osk.c: unknown oflag code in open()"));
}
static char *env = NULL;
char *
tmpnam(tmp)
char *tmp;
{
static char tmpbuf[80];
char *p, *s;
if ( env == NULL && (env = getenv("TEMP")) == NULL)
{
if (info_str ("TEMP", s, 512) != (char *) 0)
env = (strdup(s));
else
env = "/dd";
}
s = tmp == NULL ? tmpbuf : tmp;
(void) strcpy(s, env);
(void) strcat(s, "/gawkXXXXXX");
(void) mktemp(s);
return tmpbuf;
}
char *strdup(orig) /* Allocate a new copy of a string */
char *orig; /* a pointer to the original string */
{
char *copy; /* where we keep the copy. */
if (orig == (char *)NULL) /* If the original is NULL */
return (char *)NULL; /* so is the result. */
if (copy = malloc((strlen(orig) + 1) * sizeof(char)))
strcpy(copy, orig); /* if malloc() worked, copy the */
/* string data. */
return copy; /* return the result of malloc() */
} /* end of strdup() */