home *** CD-ROM | disk | FTP | other *** search
/ Super Net 1 / SUPERNET_1.iso / PC / OTROS / MSDOS / WATTCP / PISA_TAR.TAR / tar / port.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-06-24  |  2.9 KB  |  136 lines

  1. /*
  2.  * @(#)port.c 1.6    86/08/11    Public Domain, by John Gilmore, 1986
  3.  *
  4.  * These are routines not available in all environments.
  5.  *
  6.  * I know this introduces an extra level of subroutine calls and is
  7.  * slightly slower.  Frankly, my dear, I don't give a damn.  Let the
  8.  * Missed-Em Vee losers suffer a little.  This software is proud to
  9.  * have been written on a BSD system.
  10.  */
  11. #include <sys/types.h>
  12. #include <sys/stat.h>
  13. #include <signal.h>
  14. #include <errno.h>
  15.  
  16. #include "port.h"
  17.  
  18. #ifndef BSD42
  19. /*
  20.  * lstat() is a stat() which does not follow symbolic links.
  21.  * If there are no symbolic links, just use stat().
  22.  */
  23. int
  24. lstat (path, buf)
  25.     char *path;
  26.     struct stat *buf;
  27. {
  28.     extern int stat ();
  29.     return (stat (path, buf));
  30. }
  31.  
  32. /*
  33.  * valloc() does a malloc() on a page boundary.  On some systems,
  34.  * this can make large block I/O more efficient.
  35.  */
  36. char *
  37. valloc (size)
  38.     unsigned size;
  39. {
  40.     extern char *malloc ();
  41.     return (malloc (size));
  42. }
  43.  
  44. #ifndef    MSDOS
  45. /*
  46. **                NMKDIR.C
  47. **
  48. ** Written by Robert Rother, Mariah Corporation, August 1985. 
  49. **
  50. ** I wrote this out of shear disgust with myself because I couldn't
  51. ** figure out how to do this in /bin/sh.
  52. **
  53. ** If you want it, it's yours.  All I ask in return is that if you
  54. ** figure out how to do this in a Bourne Shell script you send me
  55. ** a copy.
  56. **                    sdcsvax!rmr or rmr@uscd
  57. *
  58. * Severely hacked over by John Gilmore to make a 4.2BSD compatible
  59. * subroutine.    11Mar86; hoptoad!gnu
  60. */
  61.  
  62. /*
  63.  * Make a directory.  Compatible with the mkdir() system call on 4.2BSD.
  64.  */
  65. int
  66. mkdir(dpath, dmode)
  67.     char *dpath;
  68.     int dmode;
  69. {
  70.     int cpid, status;
  71.     extern int errno;
  72.  
  73.     switch (cpid = fork()) {
  74.  
  75.     case -1:            /* Error in fork() */
  76.         return(-1);        /* Errno is set already */
  77.  
  78.     case 0:                /* Child process */
  79.         /*
  80.          * Cheap hack to set mode of new directory.  Since this
  81.          * child process is going away anyway, we zap its umask.
  82.          * FIXME, this won't suffice to set SUID, SGID, etc. on this
  83.          * directory.  Does anybody care?
  84.          */
  85.         status = umask(0);    /* Get current umask */
  86.         status = umask(status | (0777 & ~dmode)); /* Set for mkdir */
  87.         execl("/bin/mkdir", "mkdir", dpath, (char *)0);
  88.         _exit(-1);        /* Can't exec /bin/mkdir */
  89.     
  90.     default:            /* Parent process */
  91.         while (cpid != wait(&status)) ;    /* Wait for kid to finish */
  92.     }
  93.  
  94.     if (TERM_SIGNAL(status) != 0 || TERM_VALUE(status) != 0) {
  95.         errno = EIO;        /* We don't know why, but */
  96.         return -1;        /* /bin/mkdir failed */
  97.     }
  98.  
  99.     return 0;
  100. }
  101. #endif
  102. #endif
  103.  
  104. #if defined(USG)
  105. /*
  106.  * Translate V7 style into Sys V style.
  107.  */
  108. #include <string.h>
  109. #include <memory.h>
  110.  
  111. char *
  112. index (s, c)
  113.     char *s;
  114.     int c;
  115. {
  116.     return (strchr (s, c));
  117. }
  118.  
  119. char *
  120. bcopy (s1, s2, n)
  121.     char *s1, *s2;
  122.     int n;
  123. {
  124.     (void) memcpy (s2, s1, n);
  125.     return (s1);
  126. }
  127.  
  128. void
  129. bzero (s1, n)
  130.     char *s1;
  131.     int n;
  132. {
  133.     (void) memset(s1, 0, n);
  134. }
  135. #endif
  136.