home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 9 / FreshFishVol9-CD2.bin / bbs / gnu / libnix-0.8-src.lha / libnix-0.8 / sources / nix / stdio / tmpnam.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-12-12  |  530 b   |  24 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <dos/dos.h>
  4. #ifdef __GNUC__
  5. #include <inline/exec.h>
  6. #include <inline/dos.h>
  7. #endif
  8.  
  9. static char namebuffer[34];
  10.  
  11. char *tmpnam(char *s)
  12. { BPTR filelock;
  13.   static unsigned long filecount=0;
  14.   if(s==NULL)
  15.     s=namebuffer;
  16.   do /* generate a filename that doesn't exist */
  17.   { sprintf(s,"T:tempfile_2_%p_%lu",FindTask(NULL),filecount++);
  18.     filelock=Lock(s,ACCESS_WRITE);
  19.     if(filelock!=0)
  20.       UnLock(filelock);
  21.   }while(filelock!=0||IoErr()==ERROR_OBJECT_IN_USE);
  22.   return s;
  23. }
  24.