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 >
C/C++ Source or Header  |  1991-06-10  |  2KB  |  83 lines

  1. #include "osk.h"
  2. char *getenv(), *info_str(), *strdup();
  3. void *malloc();
  4.  
  5. /* open() ist #umdefiniert nach _open() */
  6. #undef open
  7.  
  8. int _open(name, oflag, mode)
  9. char *name;
  10. int oflag, mode;
  11. {
  12.    int path;
  13.    if ((oflag & O_WRONLY) != 0)
  14.    {
  15.       if (oflag & O_CREAT)
  16.          if (oflag & O_EXCL)
  17.             return (create(name, oflag & O_RDWR, oflag & O_RDWR));
  18.          else
  19.             return (creat(name, oflag & O_RDWR));
  20.       else
  21.       {
  22.          path = open(name, S_IWRITE);
  23.          if ( path >= 0  && ((oflag & O_APPEND) != 0 ) )
  24.             if (lseek(path, 2, 0) < 0)    /* ans Fileende gehen */
  25.                return(-1);
  26.          return(path);
  27.       }
  28.    }
  29.  
  30.    if ((oflag & O_RDONLY) != 0)
  31.    {
  32.       path = open(name, S_IREAD);
  33.       if ( path >= 0  && ((oflag & O_APPEND) != 0 ) )
  34.          if (lseek(path, 2, 0) < 0 )    /* ans Fileende gehen */
  35.             return(-1);
  36.       return(path);
  37.    }
  38.    else (perror("osk.c: unknown oflag code in open()"));
  39. }
  40.             
  41.  
  42. static char *env = NULL;
  43.  
  44. char *
  45. tmpnam(tmp)
  46. char *tmp;
  47. {
  48.    static char tmpbuf[80];
  49.    char *p, *s;
  50.  
  51.  
  52.    if ( env == NULL  &&  (env = getenv("TEMP")) == NULL)
  53.    {
  54.       if (info_str ("TEMP", s, 512) != (char *) 0)
  55.          env = (strdup(s));
  56.       else
  57.          env = "/dd";
  58.    }
  59.    s = tmp == NULL ? tmpbuf : tmp;
  60.  
  61.    (void) strcpy(s, env);
  62.    (void) strcat(s, "/gawkXXXXXX");
  63.    (void) mktemp(s);
  64.    return tmpbuf;
  65. }
  66.    
  67.  
  68. char *strdup(orig)    /* Allocate a new copy of a string     */
  69. char *orig;        /* a pointer to the original string     */
  70. {
  71.     char *copy;    /* where we keep the copy.        */
  72.  
  73.     if (orig == (char *)NULL)    /* If the original is NULL    */
  74.         return (char *)NULL;    /* so is the result.        */
  75.  
  76.     if (copy = malloc((strlen(orig) + 1) * sizeof(char)))
  77.         strcpy(copy, orig);    /* if malloc() worked, copy the    */
  78.                     /* string data.            */
  79.     return copy;            /* return the result of malloc() */
  80. } /* end of strdup() */
  81.  
  82.  
  83.