home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / gnu / nethack-3.1 / sys / mac / macunix.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-12-29  |  992 b   |  52 lines

  1. /*    SCCS Id: @(#)macunix.c    3.1    90/22/02
  2. /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
  3. /* NetHack may be freely redistributed.  See license for details. */
  4.  
  5. /* This file collects some Unix dependencies */
  6.  
  7. #include "hack.h"
  8. #include <fcntl.h>
  9.  
  10. int FDECL(uptodate, (int));
  11. void FDECL(regularize,(char *));
  12. void NDECL(getlock);
  13.  
  14.  
  15. int
  16. uptodate(int fd)
  17. {
  18.     return(1);
  19. }
  20.  
  21.  
  22. void
  23. regularize(char *s)
  24. {
  25.     register char *lp;
  26.  
  27.     while((lp=index(s, '.')) || (lp=index(s, ':')) )
  28.         *lp = '_';
  29. }
  30.  
  31.  
  32. void
  33. getlock( void )
  34. {
  35.     int fd ;
  36.     int pid = getpid() ; /* Process Serial Number ? */
  37.  
  38.     set_levelfile_name ( lock , 0 ) ;
  39.  
  40.     if ( ( fd = open ( lock , O_RDWR | O_EXCL | O_CREAT , LEVL_TYPE ) ) == -1 ) {
  41.         raw_printf ( "Could not lock the game %s." , lock ) ;
  42.         panic ( "Another game in progress ?" ) ;
  43.     }
  44.  
  45.     if ( write ( fd , ( char * ) & pid , sizeof ( pid ) ) != sizeof ( pid ) ) {
  46.         raw_printf ( "Could not lock the game %s." , lock ) ;
  47.         panic ( "Disk Locked ?" ) ;
  48.     }
  49.  
  50.     close ( fd ) ;
  51. }
  52.