1: /* $Header$ */
   2: 
   3: /*
   4:  * Author: Peter J. Nicklin
   5:  */
   6: #include <stdio.h>
   7: #include "path.h"
   8: #include "pld.h"
   9: #include "system.h"
  10: 
  11: #define PMODE 0644          /* file access mode */
  12: 
  13: extern int FORCE;           /* brute force approach */
  14: static char *tpld = "/tmp/...XXXXXX";   /* temporary project link directory */
  15: 
  16: /*
  17:  * restorpld() moves a project link directory from /tmp to pathname.
  18:  */
  19: void
  20: restorpld(pathname)
  21:     char *pathname;         /* project link directory pathname */
  22: {
  23:     char *pathcat();        /* pathname concatenation */
  24:     char pldpathname[PATHSIZE]; /* project link directory pathname */
  25:     int fastcopy();         /* fast file copy */
  26: 
  27:     pathcat(pldpathname, pathname, PLDNAME);
  28:     fastcopy(tpld, pldpathname);
  29:     unlink(tpld);
  30: }
  31: 
  32: 
  33: 
  34: /*
  35:  * savepld() copies a project link directory from pathname to /tmp.
  36:  * Returns 0 if successful, otherwise -1.
  37:  */
  38: savepld(pathname)
  39:     char *pathname;         /* project link directory pathname */
  40: {
  41:     char *mktemp();         /* make temporary file name */
  42:     char *pathcat();        /* pathname concatenation */
  43:     char pldpathname[PATHSIZE]; /* project link directory pathname */
  44: 
  45:     pathcat(pldpathname, pathname, PLDNAME);
  46:     return(fastcopy(pldpathname, mktemp(tpld)));
  47: }
  48: 
  49: 
  50: 
  51: /*
  52:  * unsavepld() removes the saved project link directory from /tmp.
  53:  */
  54: void
  55: unsavepld()
  56: {
  57:     unlink(tpld);
  58: }
  59: 
  60: 
  61: 
  62: /*
  63:  * fastcopy() copies f1 to f2. Returns 0 if successful, otherwise -1.
  64:  */
  65: fastcopy(f1, f2)
  66:     char *f1;           /* from file */
  67:     char *f2;           /* to file */
  68: {
  69:     register int ifd;       /* input file descriptor */
  70:     register int ofd;       /* output file descriptor */
  71:     register int n;         /* byte count */
  72:     char buf[BUFSIZ];       /* I/O buffer */
  73: 
  74:     if ((ifd = OPEN(f1, O_RDONLY, PMODE)) == -1)
  75:         if (FORCE)
  76:             return(0);
  77:         else    {
  78:             pperror(f1);
  79:             return(-1);
  80:             }
  81:     if ((ofd = CREATE(f2, O_WRONLY, PMODE)) == -1)
  82:         if (FORCE)
  83:             return(0);
  84:         else    {
  85:             pperror(f2);
  86:             return(-1);
  87:             }
  88:     while ((n = read(ifd, buf, BUFSIZ)) > 0)
  89:         if (write(ofd, buf, n) != n)
  90:             if (FORCE)
  91:                 return(0);
  92:             else    {
  93:                 pperror("");
  94:                 return(-1);
  95:                 }
  96:     close(ifd);
  97:     close(ofd);
  98:     return(0);
  99: }

Defined functions

fastcopy defined in line 65; used 3 times
restorpld defined in line 19; used 2 times
savepld defined in line 38; used 2 times
unsavepld defined in line 54; used 2 times

Defined variables

tpld defined in line 14; used 4 times

Defined macros

PMODE defined in line 11; used 2 times
Last modified: 1985-07-03
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 918
Valid CSS Valid XHTML 1.0 Strict