home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 9 Archive / 09-Archive.zip / unzip51.zip / msdos / msdos.c < prev    next >
C/C++ Source or Header  |  1994-02-06  |  41KB  |  1,123 lines

  1. /*---------------------------------------------------------------------------
  2.  
  3.   msdos.c
  4.  
  5.   MSDOS-specific routines for use with Info-ZIP's UnZip 5.1 and later.
  6.  
  7.   Contains:  Opendir()           (from zip)
  8.              Readdir()           (from zip)
  9.              do_wild()
  10.              mapattr()
  11.              mapname()
  12.              checkdir()
  13.              isfloppy()
  14.              volumelabel()       (non-djgpp, non-emx)
  15.              close_outfile()
  16.              dateformat()
  17.              _dos_setftime()     (djgpp, emx)
  18.              _dos_setfileattr()  (djgpp, emx)
  19.              _dos_getdrive()     (djgpp, emx)
  20.              _dos_creat()        (djgpp, emx)
  21.              _dos_close()        (djgpp, emx)
  22.              volumelabel()       (djgpp, emx)
  23.  
  24.   ---------------------------------------------------------------------------*/
  25.  
  26.  
  27.  
  28. #include "unzip.h"
  29. #undef FILENAME        /* BC++ 3.1 and djgpp 1.11 define FILENAME in <dir.h> */
  30.  
  31. static int isfloppy OF((int nDrive));
  32. static int volumelabel OF((char *newlabel));
  33.  
  34. static int created_dir;        /* used by mapname(), checkdir() */
  35. static int renamed_fullpath;   /* ditto */
  36. static unsigned nLabelDrive;   /* ditto, plus volumelabel() */
  37.  
  38. #if (defined(__GO32__) || defined(__EMX__))
  39. #  define MKDIR(path,mode)   mkdir(path,mode)
  40. #  include <dirent.h>        /* use readdir() */
  41. #  define direct dirent
  42. #  define Opendir opendir
  43. #  define Readdir readdir
  44. #  ifdef __EMX__
  45. #    include <dos.h>
  46. #    define GETDRIVE(d)      d = _getdrive()
  47. #    define FA_LABEL         A_LABEL
  48. #  else
  49. #    define GETDRIVE(d)      _dos_getdrive(&d)
  50. #  endif
  51. #else /* !(__GO32__ || __EMX__) */
  52. #  define MKDIR(path,mode)   mkdir(path)
  53. #  ifdef __TURBOC__
  54. #    define FATTR            FA_HIDDEN+FA_SYSTEM+FA_DIREC
  55. #    define FVOLID           FA_VOLID
  56. #    define FFIRST(n,d,a)    findfirst(n,(struct ffblk *)d,a)
  57. #    define FNEXT(d)         findnext((struct ffblk *)d)
  58. #    define GETDRIVE(d)      d=getdisk()+1
  59. #    include <dir.h>
  60. #  else /* !__TURBOC__ */
  61. #    define FATTR            _A_HIDDEN+_A_SYSTEM+_A_SUBDIR
  62. #    define FVOLID           _A_VOLID
  63. #    define FFIRST(n,d,a)    _dos_findfirst(n,a,(struct find_t *)d)
  64. #    define FNEXT(d)         _dos_findnext((struct find_t *)d)
  65. #    define GETDRIVE(d)      _dos_getdrive(&d)
  66. #    include <direct.h>
  67. #  endif /* ?__TURBOC__ */
  68.    typedef struct direct {
  69.        char d_reserved[30];
  70.        char d_name[13];
  71.        int d_first;
  72.    } DIR;
  73. #  define closedir free
  74.    DIR *Opendir OF((const char *));
  75.    struct direct *Readdir OF((DIR *));
  76.  
  77.  
  78.  
  79.  
  80. /**********************/   /* Borland C++ 3.x has its own opendir/readdir */
  81. /* Function Opendir() */   /*  library routines, but earlier versions don't, */
  82. /**********************/   /*  so use ours regardless */
  83.  
  84. DIR *Opendir(name)
  85.     const char *name;        /* name of directory to open */
  86. {
  87.     DIR *dirp;               /* malloc'd return value */
  88.     char *nbuf;              /* malloc'd temporary string */
  89.     int len = strlen(name);  /* path length to avoid strlens and strcats */
  90.  
  91.  
  92.     if ((dirp = (DIR *)malloc(sizeof(DIR))) == NULL)
  93.         return NULL;
  94.     if ((nbuf = malloc(len + 5)) == NULL) {
  95.         free(dirp);
  96.         return NULL;
  97.     }
  98.     strcpy(nbuf, name);
  99.     if (nbuf[len-1] == ':') {
  100.         nbuf[len++] = '.';
  101.     } else if (nbuf[len-1] == '/' || nbuf[len-1] == '\\')
  102.         --len;
  103.     strcpy(nbuf+len, "/*.*");
  104.     Trace((stderr, "opendir:  nbuf = [%s]\n", nbuf));
  105.  
  106.     if (FFIRST(nbuf, dirp, FATTR)) {
  107.         free((voidp *)nbuf);
  108.         return NULL;
  109.     }
  110.     free((voidp *)nbuf);
  111.     dirp->d_first = 1;
  112.     return dirp;
  113. }
  114.  
  115.  
  116.  
  117.  
  118.  
  119. /**********************/
  120. /* Function Readdir() */
  121. /**********************/
  122.  
  123. struct direct *Readdir(d)
  124.     DIR *d;         /* directory stream from which to read */
  125. {
  126.     /* Return pointer to first or next directory entry, or NULL if end. */
  127.  
  128.     if (d->d_first)
  129.         d->d_first = 0;
  130.     else
  131.         if (FNEXT(d))
  132.             return NULL;
  133.     return (struct direct *)d;
  134. }
  135.  
  136. #endif /* ?(__GO32__ || __EMX__) */
  137.  
  138.  
  139.  
  140.  
  141.  
  142. /************************/
  143. /*  Function do_wild()  */   /* identical to OS/2 version */
  144. /************************/
  145.  
  146. char *do_wild(wildspec)
  147.     char *wildspec;          /* only used first time on a given dir */
  148. {
  149.     static DIR *dir = NULL;
  150.     static char *dirname, *wildname, matchname[FILNAMSIZ];
  151.     static int firstcall=TRUE, have_dirname, dirnamelen;
  152.     struct direct *file;
  153.  
  154.  
  155.     /* Even when we're just returning wildspec, we *always* do so in
  156.      * matchname[]--calling routine is allowed to append four characters
  157.      * to the returned string, and wildspec may be a pointer to argv[].
  158.      */
  159.     if (firstcall) {        /* first call:  must initialize everything */
  160.         firstcall = FALSE;
  161.  
  162.         /* break the wildspec into a directory part and a wildcard filename */
  163.         if ((wildname = strrchr(wildspec, '/')) == NULL &&
  164.             (wildname = strrchr(wildspec, ':')) == NULL) {
  165.             dirname = ".";
  166.             dirnamelen = 1;
  167.             have_dirname = FALSE;
  168.             wildname = wildspec;
  169.         } else {
  170.             ++wildname;     /* point at character after '/' or ':' */
  171.             dirnamelen = wildname - wildspec;
  172.             if ((dirname = (char *)malloc(dirnamelen+1)) == NULL) {
  173.                 fprintf(stderr, "warning:  can't allocate wildcard buffers\n");
  174.                 strcpy(matchname, wildspec);
  175.                 return matchname;   /* but maybe filespec was not a wildcard */
  176.             }
  177. /* GRR:  can't strip trailing char for opendir since might be "d:/" or "d:"
  178.  *       (would have to check for "./" at end--let opendir handle it instead) */
  179.             strncpy(dirname, wildspec, dirnamelen);
  180.             dirname[dirnamelen] = '\0';   /* terminate for strcpy below */
  181.             have_dirname = TRUE;
  182.         }
  183.         Trace((stderr, "do_wild:  dirname = [%s]\n", dirname));
  184.  
  185.         if ((dir = Opendir(dirname)) != NULL) {
  186.             while ((file = Readdir(dir)) != NULL) {
  187.                 Trace((stderr, "do_wild:  readdir returns %s\n", file->d_name));
  188.                 if (match(file->d_name, wildname, 1)) {  /* 1 == ignore case */
  189.                     Trace((stderr, "do_wild:  match() succeeds\n"));
  190.                     if (have_dirname) {
  191.                         strcpy(matchname, dirname);
  192.                         strcpy(matchname+dirnamelen, file->d_name);
  193.                     } else
  194.                         strcpy(matchname, file->d_name);
  195.                     return matchname;
  196.                 }
  197.             }
  198.             /* if we get to here directory is exhausted, so close it */
  199.             closedir(dir);
  200.             dir = NULL;
  201.         }
  202.         Trace((stderr, "do_wild:  opendir(%s) returns NULL\n", dirname));
  203.  
  204.         /* return the raw wildspec in case that works (e.g., directory not
  205.          * searchable, but filespec was not wild and file is readable) */
  206.         strcpy(matchname, wildspec);
  207.         return matchname;
  208.     }
  209.  
  210.     /* last time through, might have failed opendir but returned raw wildspec */
  211.     if (dir == NULL) {
  212.         firstcall = TRUE;  /* nothing left to try--reset for new wildspec */
  213.         if (have_dirname)
  214.             free(dirname);
  215.         return (char *)NULL;
  216.     }
  217.  
  218.     /* If we've gotten this far, we've read and matched at least one entry
  219.      * successfully (in a previous call), so dirname has been copied into
  220.      * matchname already.
  221.      */
  222.     while ((file = Readdir(dir)) != NULL)
  223.         if (match(file->d_name, wildname, 1)) {   /* 1 == ignore case */
  224.             if (have_dirname) {
  225.                 /* strcpy(matchname, dirname); */
  226.                 strcpy(matchname+dirnamelen, file->d_name);
  227.             } else
  228.                 strcpy(matchname, file->d_name);
  229.             return matchname;
  230.         }
  231.  
  232.     closedir(dir);     /* have read at least one dir entry; nothing left */
  233.     dir = NULL;
  234.     firstcall = TRUE;  /* reset for new wildspec */
  235.     if (have_dirname)
  236.         free(dirname);
  237.     return (char *)NULL;
  238.  
  239. } /* end function do_wild() */
  240.  
  241.  
  242.  
  243.  
  244.  
  245. /**********************/
  246. /* Function mapattr() */
  247. /**********************/
  248.  
  249. int mapattr()
  250. {
  251.     /* set archive bit (file is not backed up): */
  252.     pInfo->file_attr = (unsigned)(crec.external_file_attributes | 32) & 0xff;
  253.     return 0;
  254.  
  255. } /* end function mapattr() */
  256.  
  257.  
  258.  
  259.  
  260.  
  261. /************************/
  262. /*  Function mapname()  */
  263. /************************/
  264.  
  265. int mapname(renamed)  /* return 0 if no error, 1 if caution (filename trunc), */
  266.     int renamed;      /* 2 if warning (skip file because dir doesn't exist), */
  267. {                     /* 3 if error (skip file), 10 if no memory (skip file) */
  268.     char pathcomp[FILNAMSIZ];   /* path-component buffer */
  269.     char *pp, *cp=NULL;         /* character pointers */
  270.     char *lastsemi = NULL;      /* pointer to last semi-colon in pathcomp */
  271.     char *last_dot = NULL;      /* last dot not converted to underscore */
  272.     int quote = FALSE;          /* flag:  next char is literal */
  273.     int dotname = FALSE;        /* flag:  path component begins with dot */
  274.     int error = 0;
  275.     register unsigned workch;   /* hold the character being tested */
  276.  
  277.  
  278. /*---------------------------------------------------------------------------
  279.     Initialize various pointers and counters and stuff.
  280.   ---------------------------------------------------------------------------*/
  281.  
  282.     /* can create path as long as not just freshening, or if user told us */
  283.     create_dirs = (!fflag || renamed);
  284.  
  285.     created_dir = FALSE;        /* not yet */
  286.     renamed_fullpath = FALSE;
  287.  
  288. /* GRR:  for VMS, convert to internal format now or later? or never? */
  289.     if (renamed) {
  290.         cp = filename - 1;      /* point to beginning of renamed name... */
  291.         while (*++cp)
  292.             if (*cp == '\\')    /* convert backslashes to forward */
  293.                 *cp = '/';
  294.         cp = filename;
  295.         /* use temporary rootpath if user gave full pathname */
  296.         if (filename[0] == '/') {
  297.             renamed_fullpath = TRUE;
  298.             pathcomp[0] = '/';  /* copy the '/' and terminate */
  299.             pathcomp[1] = '\0';
  300.             ++cp;
  301.         } else if (isalpha(filename[0]) && filename[1] == ':') {
  302.             renamed_fullpath = TRUE;
  303.             pp = pathcomp;
  304.             *pp++ = *cp++;      /* copy the "d:" (+ '/', possibly) */
  305.             *pp++ = *cp++;
  306.             if (*cp == '/')
  307.                 *pp++ = *cp++;  /* otherwise add "./"? */
  308.             *pp = '\0';
  309.         }
  310.     }
  311.  
  312.     /* pathcomp is ignored unless renamed_fullpath is TRUE: */
  313.     if ((error = checkdir(pathcomp, INIT)) != 0)    /* initialize path buffer */
  314.         return error;           /* ...unless no mem or vol label on hard disk */
  315.  
  316.     *pathcomp = '\0';           /* initialize translation buffer */
  317.     pp = pathcomp;              /* point to translation buffer */
  318.     if (!renamed) {             /* cp already set if renamed */
  319.         if (jflag)              /* junking directories */
  320.             cp = (char *)strrchr(filename, '/');
  321.         if (cp == NULL)         /* no '/' or not junking dirs */
  322.             cp = filename;      /* point to internal zipfile-member pathname */
  323.         else
  324.             ++cp;               /* point to start of last component of path */
  325.     }
  326.  
  327. /*---------------------------------------------------------------------------
  328.     Begin main loop through characters in filename.
  329.   ---------------------------------------------------------------------------*/
  330.  
  331.     while ((workch = (uch)*cp++) != 0) {
  332.  
  333.         if (quote) {              /* if character quoted, */
  334.             *pp++ = (char)workch; /*  include it literally */
  335.             quote = FALSE;
  336.         } else
  337.             switch (workch) {
  338.             case '/':             /* can assume -j flag not given */
  339.                 *pp = '\0';
  340. /* GRR:  can add 8.3 truncation here */
  341.                 if (last_dot) {   /* one dot in directory name is legal */
  342.                     *last_dot = '.';
  343.                     last_dot = NULL;
  344.                 }
  345.                 if ((error = checkdir(pathcomp, APPEND_DIR)) > 1)
  346.                     return error;
  347.                 pp = pathcomp;    /* reset conversion buffer for next piece */
  348.                 lastsemi = NULL;  /* leave directory semi-colons alone */
  349.                 break;
  350.  
  351.             case ':':             /* drive names not stored in zipfile, */
  352.             case '[':             /*  so no colons allowed; no brackets, */
  353.             case ']':             /*  either */
  354.                 *pp++ = '_';
  355.                 break;
  356.  
  357.             case '.':
  358.                 if (pp == pathcomp) {     /* nothing appended yet... */
  359.                     if (*cp == '/') {     /* don't bother appending a "./" */
  360.                         ++cp;             /*  component to the path:  skip */
  361.                         break;            /*  to next char after the '/' */
  362.                     } else if (*cp == '.' && cp[1] == '/') {   /* "../" */
  363.                         *pp++ = '.';      /* add first dot, unchanged... */
  364.                         ++cp;             /* skip second dot, since it will */
  365.                     } else {              /*  be "added" at end of if-block */
  366.                         *pp++ = '_';      /* FAT doesn't allow null filename */
  367.                         dotname = TRUE;   /*  bodies, so map .exrc -> _.exrc */
  368.                     }                     /*  (extra '_' now, "dot" below) */
  369.                 } else if (dotname) {     /* found a second dot, but still */
  370.                     dotname = FALSE;      /*  have extra leading underscore: */
  371.                     *pp = '\0';           /*  remove it by shifting chars */
  372.                     pp = pathcomp + 1;    /*  left one space (e.g., .p1.p2: */
  373.                     while (pp[1]) {       /*  __p1 -> _p1_p2 -> _p1.p2 when */
  374.                         *pp = pp[1];      /*  finished) [opt.:  since first */
  375.                         ++pp;             /*  two chars are same, can start */
  376.                     }                     /*  shifting at second position] */
  377.                 }
  378.                 last_dot = pp;    /* point at last dot so far... */
  379.                 *pp++ = '_';      /* convert dot to underscore for now */
  380.                 break;
  381.  
  382.             case ';':             /* start of VMS version? */
  383.                 lastsemi = pp;    /* omit for now; remove VMS vers. later */
  384.                 break;
  385.  
  386.             case '\026':          /* control-V quote for special chars */
  387.                 quote = TRUE;     /* set flag for next character */
  388.                 break;
  389.  
  390.             case ' ':             /* change spaces to underscore only */
  391.                 if (sflag)        /*  if specifically requested */
  392.                     *pp++ = '_';
  393.                 else
  394.                     *pp++ = (char)workch;
  395.                 break;
  396.  
  397.             default:
  398.                 /* allow European characters in filenames: */
  399.                 if (isprint(workch) || (128 <= workch && workch <= 254))
  400.                     *pp++ = (char)workch;
  401.             } /* end switch */
  402.  
  403.     } /* end while loop */
  404.  
  405.     *pp = '\0';                   /* done with pathcomp:  terminate it */
  406.  
  407.     /* if not saving them, remove VMS version numbers (appended "###") */
  408.     if (!V_flag && lastsemi) {
  409.         pp = lastsemi;            /* semi-colon was omitted:  expect all #'s */
  410.         while (isdigit((uch)(*pp)))
  411.             ++pp;
  412.         if (*pp == '\0')          /* only digits between ';' and end:  nuke */
  413.             *lastsemi = '\0';
  414.     }
  415.  
  416. /* GRR:  can add 8.3 truncation here */
  417.     if (last_dot != NULL)         /* one dot is OK:  put it back in */
  418.         *last_dot = '.';          /* (already done for directories) */
  419.  
  420. /*---------------------------------------------------------------------------
  421.     Report if directory was created (and no file to create:  filename ended
  422.     in '/'), check name to be sure it exists, and combine path and name be-
  423.     fore exiting.
  424.   ---------------------------------------------------------------------------*/
  425.  
  426.     if (filename[strlen(filename) - 1] == '/') {
  427.         checkdir(filename, GETPATH);
  428.         if (created_dir && QCOND2) {
  429.             fprintf(stdout, "   creating: %s\n", filename);
  430.             return IZ_CREATED_DIR;   /* set dir time (note trailing '/') */
  431.         }
  432.         return 2;   /* dir existed already; don't look for data to extract */
  433.     }
  434.  
  435.     if (*pathcomp == '\0') {
  436.         fprintf(stderr, "mapname:  conversion of %s failed\n", filename);
  437.         return 3;
  438.     }
  439.  
  440.     checkdir(pathcomp, APPEND_NAME);   /* returns 1 if truncated:  care? */
  441.     checkdir(filename, GETPATH);
  442.  
  443.     if (pInfo->vollabel) {   /* set the volume label now */
  444.         if (QCOND2)
  445.             fprintf(stdout, "labelling %c: %-22s\n", (nLabelDrive + 'a' - 1),
  446.               filename);
  447.         if (volumelabel(filename)) {
  448.             fprintf(stderr, "mapname:  error setting volume label\n");
  449.             return 3;
  450.         }
  451.         return 2;   /* success:  skip the "extraction" quietly */
  452.     }
  453.  
  454.     return error;
  455.  
  456. } /* end function mapname() */
  457.  
  458.  
  459.  
  460.  
  461.  
  462. /***********************/
  463. /* Function checkdir() */
  464. /***********************/
  465.  
  466. int checkdir(pathcomp, flag)
  467.     char *pathcomp;
  468.     int flag;
  469. /*
  470.  * returns:  1 - (on APPEND_NAME) truncated filename
  471.  *           2 - path doesn't exist, not allowed to create
  472.  *           3 - path doesn't exist, tried to create and failed; or
  473.  *               path exists and is not a directory, but is supposed to be
  474.  *           4 - path is too long
  475.  *          10 - can't allocate memory for filename buffers
  476.  */
  477. {
  478.     static int rootlen = 0;   /* length of rootpath */
  479.     static char *rootpath;    /* user's "extract-to" directory */
  480.     static char *buildpath;   /* full path (so far) to extracted file */
  481.     static char *end;         /* pointer to end of buildpath ('\0') */
  482. #ifdef MSC
  483.     int attrs;                /* work around MSC stat() bug */
  484. #endif
  485.  
  486. #   define FN_MASK   7
  487. #   define FUNCTION  (flag & FN_MASK)
  488.  
  489.  
  490.  
  491. /*---------------------------------------------------------------------------
  492.     APPEND_DIR:  append the path component to the path being built and check
  493.     for its existence.  If doesn't exist and we are creating directories, do
  494.     so for this one; else signal success or error as appropriate.
  495.   ---------------------------------------------------------------------------*/
  496.  
  497.     if (FUNCTION == APPEND_DIR) {
  498.         int too_long = FALSE;
  499.  
  500.         Trace((stderr, "appending dir segment [%s]\n", pathcomp));
  501.         while ((*end = *pathcomp++) != '\0')
  502.             ++end;
  503.  
  504.         /* GRR:  could do better check, see if overrunning buffer as we go:
  505.          * check end-buildpath after each append, set warning variable if
  506.          * within 20 of FILNAMSIZ; then if var set, do careful check when
  507.          * appending.  Clear variable when begin new path. */
  508.  
  509.         if ((end-buildpath) > FILNAMSIZ-3)  /* need '/', one-char name, '\0' */
  510.             too_long = TRUE;                /* check if extracting directory? */
  511. #ifdef MSC /* MSC 6.00 bug:  stat(non-existent-dir) == 0 [exists!] */
  512.         if (_dos_getfileattr(buildpath, &attrs) || stat(buildpath, &statbuf))  
  513. #else
  514.         if (stat(buildpath, &statbuf))      /* path doesn't exist */
  515. #endif
  516.         {
  517.             if (!create_dirs) {   /* told not to create (freshening) */
  518.                 free(buildpath);
  519.                 return 2;         /* path doesn't exist:  nothing to do */
  520.             }
  521.             if (too_long) {
  522.                 fprintf(stderr, "checkdir error:  path too long: %s\n",
  523.                   buildpath);
  524.                 fflush(stderr);
  525.                 free(buildpath);
  526.                 return 4;         /* no room for filenames:  fatal */
  527.             }
  528.             if (MKDIR(buildpath, 0777) == -1) {   /* create the directory */
  529.                 fprintf(stderr, "checkdir error:  can't create %s\n\
  530.                  unable to process %s.\n", buildpath, filename);
  531.                 fflush(stderr);
  532.                 free(buildpath);
  533.                 return 3;      /* path didn't exist, tried to create, failed */
  534.             }
  535.             created_dir = TRUE;
  536.         } else if (!S_ISDIR(statbuf.st_mode)) {
  537.             fprintf(stderr, "checkdir error:  %s exists but is not directory\n\
  538.                  unable to process %s.\n", buildpath, filename);
  539.             fflush(stderr);
  540.             free(buildpath);
  541.             return 3;          /* path existed but wasn't dir */
  542.         }
  543.         if (too_long) {
  544.             fprintf(stderr, "checkdir error:  path too long: %s\n", buildpath);
  545.             fflush(stderr);
  546.             free(buildpath);
  547.             return 4;         /* no room for filenames:  fatal */
  548.         }
  549.         *end++ = '/';
  550.         *end = '\0';
  551.         Trace((stderr, "buildpath now = [%s]\n", buildpath));
  552.         return 0;
  553.  
  554.     } /* end if (FUNCTION == APPEND_DIR) */
  555.  
  556. /*---------------------------------------------------------------------------
  557.     GETPATH:  copy full path to the string pointed at by pathcomp, and free
  558.     buildpath.
  559.   ---------------------------------------------------------------------------*/
  560.  
  561.     if (FUNCTION == GETPATH) {
  562.         strcpy(pathcomp, buildpath);
  563.         Trace((stderr, "getting and freeing path [%s]\n", pathcomp));
  564.         free(buildpath);
  565.         buildpath = end = NULL;
  566.         return 0;
  567.     }
  568.  
  569. /*---------------------------------------------------------------------------
  570.     APPEND_NAME:  assume the path component is the filename; append it and
  571.     return without checking for existence.
  572.   ---------------------------------------------------------------------------*/
  573.  
  574.     if (FUNCTION == APPEND_NAME) {
  575.         Trace((stderr, "appending filename [%s]\n", pathcomp));
  576.         while ((*end = *pathcomp++) != '\0') {
  577.             ++end;
  578.             if ((end-buildpath) >= FILNAMSIZ) {
  579.                 *--end = '\0';
  580.                 fprintf(stderr, "checkdir warning:  path too long; truncating\n\
  581. checkdir warning:  path too long; truncating\n\
  582.                    %s\n                -> %s\n", filename, buildpath);
  583.                 fflush(stderr);
  584.                 return 1;   /* filename truncated */
  585.             }
  586.         }
  587.         Trace((stderr, "buildpath now = [%s]\n", buildpath));
  588.         return 0;  /* could check for existence here, prompt for new name... */
  589.     }
  590.  
  591. /*---------------------------------------------------------------------------
  592.     INIT:  allocate and initialize buffer space for the file currently being
  593.     extracted.  If file was renamed with an absolute path, don't prepend the
  594.     extract-to path.
  595.   ---------------------------------------------------------------------------*/
  596.  
  597.     if (FUNCTION == INIT) {
  598.         Trace((stderr, "initializing buildpath to "));
  599.         if ((buildpath = (char *)malloc(strlen(filename)+rootlen+1)) == NULL)
  600.             return 10;
  601.         if (pInfo->vollabel) {
  602. /* GRR:  for network drives, do strchr() and return IZ_VOL_LABEL if not [1] */
  603.             if (renamed_fullpath && pathcomp[1] == ':')
  604.                 *buildpath = ToLower(*pathcomp);
  605.             else if (!renamed_fullpath && rootpath && rootpath[1] == ':')
  606.                 *buildpath = ToLower(*rootpath);
  607.             else {
  608.                 GETDRIVE(nLabelDrive);   /* assumed that a == 1, b == 2, etc. */
  609.                 *buildpath = (char)(nLabelDrive - 1 + 'a');
  610.             }
  611.             nLabelDrive = *buildpath - 'a' + 1;       /* save for mapname() */
  612.             if (volflag == 0 || *buildpath < 'a' ||   /* no labels/bogus disk */
  613.                 (volflag == 1 && !isfloppy(nLabelDrive))) {  /* -$:  no fixed */
  614.                 free(buildpath);
  615.                 return IZ_VOL_LABEL;     /* skipping with message */
  616.             }
  617.             *buildpath = '\0';
  618.             end = buildpath;
  619.         } else if (renamed_fullpath) {   /* pathcomp = valid data */
  620.             end = buildpath;
  621.             while ((*end = *pathcomp++) != '\0')
  622.                 ++end;
  623.         } else if (rootlen > 0) {
  624.             strcpy(buildpath, rootpath);
  625.             end = buildpath + rootlen;
  626.         } else {
  627.             *buildpath = '\0';
  628.             end = buildpath;
  629.         }
  630.         Trace((stderr, "[%s]\n", buildpath));
  631.         return 0;
  632.     }
  633.  
  634. /*---------------------------------------------------------------------------
  635.     ROOT:  if appropriate, store the path in rootpath and create it if neces-
  636.     sary; else assume it's a zipfile member and return.  This path segment
  637.     gets used in extracting all members from every zipfile specified on the
  638.     command line.  Note that under OS/2 and MS-DOS, if a candidate extract-to
  639.     directory specification includes a drive letter (leading "x:"), it is
  640.     treated just as if it had a trailing '/'--that is, one directory level
  641.     will be created if the path doesn't exist, unless this is otherwise pro-
  642.     hibited (e.g., freshening).
  643.   ---------------------------------------------------------------------------*/
  644.  
  645. /* GRR:  for VMS and TOPS-20, allow either y]z.dir or y.z] forms; fix as
  646.  * appropriate before stat call */
  647.  
  648. /* GRR:  for MS-DOS and OS/2, necessary to append '.' to path of form "x:"? */
  649.  
  650.     if (FUNCTION == ROOT) {
  651.         Trace((stderr, "initializing root path to [%s]\n", pathcomp));
  652.         if (pathcomp == NULL) {
  653.             rootlen = 0;
  654.             return 0;
  655.         }
  656.         if ((rootlen = strlen(pathcomp)) > 0) {
  657.             int had_trailing_pathsep=FALSE, has_drive=FALSE, xtra=2;
  658.  
  659.             if (isalpha(pathcomp[0]) && pathcomp[1] == ':')
  660.                 has_drive = TRUE;   /* drive designator */
  661.             if (pathcomp[rootlen-1] == '/') {
  662.                 pathcomp[--rootlen] = '\0';
  663.                 had_trailing_pathsep = TRUE;
  664.             }
  665.             if (has_drive && (rootlen == 2)) {
  666.                 if (!had_trailing_pathsep)   /* i.e., original wasn't "x:/" */
  667.                     xtra = 3;      /* room for '.' + '/' + 0 at end of "x:" */
  668.             } else {               /* don't bother checking "x:." and "x:/" */
  669. #ifdef MSC /* MSC 6.00 bug:  stat(non-existent-dir) == 0 [exists!] */
  670.                 if (_dos_getfileattr(pathcomp, &attrs) ||
  671.                     SSTAT(pathcomp, &statbuf) || !S_ISDIR(statbuf.st_mode))
  672. #else
  673.                 if (SSTAT(pathcomp, &statbuf) || !S_ISDIR(statbuf.st_mode))
  674. #endif
  675.                 {
  676.                     /* path does not exist */
  677.                     if (!create_dirs
  678. #ifdef OLD_EXDIR
  679.                                      || (!has_drive && !had_trailing_pathsep)
  680. #endif
  681.                                                                              ) {
  682.                         rootlen = 0;
  683.                         return 2;   /* treat as stored file */
  684.                     }
  685. /* GRR:  scan for wildcard characters?  OS-dependent...  if find any, return 2:
  686.  * treat as stored file(s) */
  687.                     /* create directory (could add loop here to scan pathcomp
  688.                      * and create more than one level, but really necessary?) */
  689.                     if (MKDIR(pathcomp, 0777) == -1) {
  690.                         fprintf(stderr,
  691.                           "checkdir:  can't create extraction directory: %s\n",
  692.                           pathcomp);
  693.                         fflush(stderr);
  694.                         rootlen = 0;   /* path didn't exist, tried to create, */
  695.                         return 3;  /* failed:  file exists, or need 2+ levels */
  696.                     }
  697.                 }
  698.             }
  699.             if ((rootpath = (char *)malloc(rootlen+xtra)) == NULL) {
  700.                 rootlen = 0;
  701.                 return 10;
  702.             }
  703.             strcpy(rootpath, pathcomp);
  704.             if (xtra == 3)                  /* had just "x:", make "x:." */
  705.                 rootpath[rootlen++] = '.';
  706.             rootpath[rootlen++] = '/';
  707.             rootpath[rootlen] = '\0';
  708.         }
  709.         Trace((stderr, "rootpath now = [%s]\n", rootpath));
  710.         return 0;
  711.     }
  712.  
  713. /*---------------------------------------------------------------------------
  714.     END:  free rootpath, immediately prior to program exit.
  715.   ---------------------------------------------------------------------------*/
  716.  
  717.     if (FUNCTION == END) {
  718.         Trace((stderr, "freeing rootpath\n"));
  719.         if (rootlen > 0)
  720.             free(rootpath);
  721.         return 0;
  722.     }
  723.  
  724.     return 99;  /* should never reach */
  725.  
  726. } /* end function checkdir() */
  727.  
  728.  
  729.  
  730.  
  731.  
  732.  
  733. /***********************/
  734. /* Function isfloppy() */
  735. /***********************/
  736.  
  737. static int isfloppy(nDrive)  /* more precisely, is it removable? */
  738.     int nDrive;
  739. {
  740.     union REGS regs;
  741.  
  742.     regs.h.ah = 0x44;
  743.     regs.h.al = 0x08;
  744.     regs.h.bl = (uch)nDrive;
  745. #ifdef __EMX__
  746.     _int86(0x21, ®s, ®s);
  747.     if (regs.x.flags & 1)
  748. #else
  749.     intdos(®s, ®s);
  750.     if (regs.x.cflag)        /* error:  do default a/b check instead */
  751. #endif
  752.     {
  753.         Trace((stderr,
  754.           "error in DOS function 0x44 (AX = 0x%04x):  guessing instead...\n",
  755.           regs.x.ax));
  756.         return (nDrive == 1 || nDrive == 2)? TRUE : FALSE;
  757.     } else
  758.         return regs.x.ax? FALSE : TRUE;
  759. }
  760.  
  761.  
  762.  
  763.  
  764. #if (!defined(__GO32__) && !defined(__EMX__))
  765.  
  766. typedef struct dosfcb {
  767.     uch  flag;        /* ff to indicate extended FCB */
  768.     char res[5];      /* reserved */
  769.     uch  vattr;       /* attribute */
  770.     uch  drive;       /* drive (1=A, 2=B, ...) */
  771.     uch  vn[11];      /* file or volume name */
  772.     char dmmy[5];
  773.     uch  nn[11];      /* holds new name if renaming (else reserved) */
  774.     char dmmy2[9];
  775. } dos_fcb;
  776.  
  777. /**************************/
  778. /* Function volumelabel() */
  779. /**************************/
  780.  
  781. static int volumelabel(newlabel)
  782.     char *newlabel;
  783. {
  784. #ifdef DEBUG
  785.     char *p;
  786. #endif
  787.     int len = strlen(newlabel);
  788.     dos_fcb  fcb, dta, far *pfcb=&fcb, far *pdta=&dta;
  789.     struct SREGS sregs;
  790.     union REGS regs;
  791.  
  792.  
  793. /*---------------------------------------------------------------------------
  794.     Label the diskette specified by nLabelDrive using FCB calls.  (Old ver-
  795.     sions of MS-DOS and OS/2 DOS boxes can't use DOS function 3Ch to create
  796.     labels.)  Must use far pointers for MSC FP_* macros to work; must pad
  797.     FCB filenames with spaces; and cannot include dot in 8th position.  May
  798.     or may not need to zero out FCBs before using; do so just in case.
  799.   ---------------------------------------------------------------------------*/
  800.  
  801.     memset((char *)&dta, 0, sizeof(dos_fcb));
  802.     memset((char *)&fcb, 0, sizeof(dos_fcb));
  803.  
  804. #ifdef DEBUG
  805.     for (p = (char *)&dta; (p - (char *)&dta) < sizeof(dos_fcb); ++p)
  806.         if (*p)
  807.             fprintf(stderr, "error:  dta[%d] = %x\n", (p - (char *)&dta), *p);
  808.     for (p = (char *)&fcb; (p - (char *)&fcb) < sizeof(dos_fcb); ++p)
  809.         if (*p)
  810.             fprintf(stderr, "error:  fcb[%d] = %x\n", (p - (char *)&fcb), *p);
  811.     printf("testing pointer macros:\n");
  812.     segread(&sregs);
  813.     printf("cs = %x, ds = %x, es = %x, ss = %x\n", sregs.cs, sregs.ds, sregs.es,
  814.       sregs.ss);
  815. #endif /* DEBUG */
  816.  
  817. #if 0
  818. #ifdef __TURBOC__
  819.     bdosptr(0x1a, dta, DO_NOT_CARE);
  820. #else
  821.     (intdosx method below)
  822. #endif
  823. #endif /* 0 */
  824.  
  825.     /* set the disk transfer address for subsequent FCB calls */
  826.     sregs.ds = FP_SEG(pdta);
  827.     regs.x.dx = FP_OFF(pdta);
  828.     Trace((stderr, "segment:offset of pdta = %x:%x\n", sregs.ds, regs.x.dx));
  829.     Trace((stderr, "&dta = %lx, pdta = %lx\n", (ulg)&dta, (ulg)pdta));
  830.     regs.h.ah = 0x1a;
  831.     intdosx(®s, ®s, &sregs);
  832.  
  833.     /* fill in the FCB */
  834.     sregs.ds = FP_SEG(pfcb);
  835.     regs.x.dx = FP_OFF(pfcb);
  836.     pfcb->flag = 0xff;          /* extended FCB */
  837.     pfcb->vattr = 0x08;         /* attribute:  disk volume label */
  838.     pfcb->drive = (uch)nLabelDrive;
  839.  
  840. #ifdef DEBUG
  841.     Trace((stderr, "segment:offset of pfcb = %x:%x\n", sregs.ds, regs.x.dx));
  842.     Trace((stderr, "&fcb = %lx, pfcb = %lx\n", (ulg)&fcb, (ulg)pfcb));
  843.     Trace((stderr, "(2nd check:  labelling drive %c:)\n", pfcb->drive-1+'A'));
  844.     if (pfcb->flag != fcb.flag)
  845.         fprintf(stderr, "error:  pfcb->flag = %d, fcb.flag = %d\n",
  846.           pfcb->flag, fcb.flag);
  847.     if (pfcb->drive != fcb.drive)
  848.         fprintf(stderr, "error:  pfcb->drive = %d, fcb.drive = %d\n",
  849.           pfcb->drive, fcb.drive);
  850.     if (pfcb->vattr != fcb.vattr)
  851.         fprintf(stderr, "error:  pfcb->vattr = %d, fcb.vattr = %d\n",
  852.           pfcb->vattr, fcb.vattr);
  853. #endif /* DEBUG */
  854.  
  855.     /* check for existing label */
  856.     Trace((stderr, "searching for existing label via FCBs\n"));
  857.     regs.h.ah = 0x11;      /* FCB find first */
  858. #if 0  /* THIS STRNCPY FAILS (MSC bug?): */
  859.     strncpy(pfcb->vn, "???????????", 11);   /* i.e., "*.*" */
  860.     Trace((stderr, "pfcb->vn = %lx\n", (ulg)pfcb->vn));
  861.     Trace((stderr, "flag = %x, drive = %d, vattr = %x, vn = %s = %s.\n",
  862.       fcb.flag, fcb.drive, fcb.vattr, fcb.vn, pfcb->vn));
  863. #endif
  864.     strncpy((char *)fcb.vn, "???????????", 11);   /* i.e., "*.*" */
  865.     Trace((stderr, "fcb.vn = %lx\n", (ulg)fcb.vn));
  866.     Trace((stderr, "regs.h.ah = %x, regs.x.dx = %04x, sregs.ds = %04x\n",
  867.       regs.h.ah, regs.x.dx, sregs.ds));
  868.     Trace((stderr, "flag = %x, drive = %d, vattr = %x, vn = %s = %s.\n",
  869.       fcb.flag, fcb.drive, fcb.vattr, fcb.vn, pfcb->vn));
  870.     intdosx(®s, ®s, &sregs);
  871.  
  872. /*---------------------------------------------------------------------------
  873.     If not previously labelled, write a new label.  Otherwise just rename,
  874.     since MS-DOS 2.x has a bug which damages the FAT when the old label is
  875.     deleted.
  876.   ---------------------------------------------------------------------------*/
  877.  
  878.     if (regs.h.al) {
  879.         Trace((stderr, "no label found\n\n"));
  880.         regs.h.ah = 0x16;                 /* FCB create file */
  881.         strncpy((char *)fcb.vn, newlabel, len);
  882.         if (len < 11)   /* fill with spaces */
  883.             strncpy((char *)(fcb.vn+len), "           ", 11-len);
  884.         Trace((stderr, "fcb.vn = %lx  pfcb->vn = %lx\n", (ulg)fcb.vn,
  885.           (ulg)pfcb->vn));
  886.         Trace((stderr, "flag = %x, drive = %d, vattr = %x\n", fcb.flag,
  887.           fcb.drive, fcb.vattr));
  888.         Trace((stderr, "vn = %s = %s.\n", fcb.vn, pfcb->vn));
  889.         intdosx(®s, ®s, &sregs);
  890.         regs.h.ah = 0x10;                 /* FCB close file */
  891.         if (regs.h.al) {
  892.             Trace((stderr, "unable to write volume name (AL = %x)\n",
  893.               regs.h.al));
  894.             intdosx(®s, ®s, &sregs);
  895.             return 1;
  896.         } else {
  897.             intdosx(®s, ®s, &sregs);
  898.             Trace((stderr, "new volume label [%s] written\n", newlabel));
  899.             return 0;
  900.         }
  901.     } else {
  902.         Trace((stderr, "found old label [%s]\n\n", dta.vn));  /* not term. */
  903.         regs.h.ah = 0x17;                 /* FCB rename */
  904.         strncpy((char *)fcb.vn, (char *)dta.vn, 11);
  905.         strncpy((char *)fcb.nn, newlabel, len);
  906.         if (len < 11)                     /* fill with spaces */
  907.             strncpy((char *)(fcb.nn+len), "           ", 11-len);
  908.         Trace((stderr, "fcb.vn = %lx  pfcb->vn = %lx\n", (ulg)fcb.vn,
  909.           (ulg)pfcb->vn));
  910.         Trace((stderr, "fcb.nn = %lx  pfcb->nn = %lx\n", (ulg)fcb.nn,
  911.           (ulg)pfcb->nn));
  912.         Trace((stderr, "flag = %x, drive = %d, vattr = %x\n", fcb.flag,
  913.           fcb.drive, fcb.vattr));
  914.         Trace((stderr, "vn = %s = %s.\n", fcb.vn, pfcb->vn));
  915.         Trace((stderr, "nn = %s = %s.\n", fcb.nn, pfcb->nn));
  916.         intdosx(®s, ®s, &sregs);
  917.         if (regs.h.al) {
  918.             Trace((stderr, "Unable to change volume name (AL = %x)\n",
  919.               regs.h.al));
  920.             return 1;
  921.         } else {
  922.             Trace((stderr, "volume label changed to [%s]\n", newlabel));
  923.             return 0;
  924.         }
  925.     }
  926. } /* end function volumelabel() */
  927.  
  928. #endif /* !__GO32__ && !__EMX__ */
  929.  
  930.  
  931.  
  932.  
  933.  
  934. /****************************/
  935. /* Function close_outfile() */
  936. /****************************/
  937.  
  938. void close_outfile()
  939.  /*
  940.   * MS-DOS VERSION
  941.   *
  942.   * Set the output file date/time stamp according to information from the
  943.   * zipfile directory record for this member, then close the file and set
  944.   * its permissions (archive, hidden, read-only, system).  Aside from closing
  945.   * the file, this routine is optional (but most compilers support it).
  946.   */
  947. {
  948. #ifdef __TURBOC__
  949.     union {
  950.         struct ftime ft;        /* system file time record */
  951.         struct {
  952.             ush ztime;          /* date and time words */
  953.             ush zdate;          /* .. same format as in .ZIP file */
  954.         } zt;
  955.     } td;
  956. #endif
  957.  
  958.  
  959. /*---------------------------------------------------------------------------
  960.     Copy and/or convert time and date variables, if necessary; then set the
  961.     file time/date.  WEIRD BORLAND "BUG":  if output is buffered, and if run
  962.     under at least some versions of DOS (e.g., 6.0), and if files are smaller
  963.     than DOS physical block size (i.e., 512 bytes) (?), then files MAY NOT
  964.     get timestamped correctly--apparently setftime() occurs before any data
  965.     are written to the file, and when file is closed and buffers are flushed,
  966.     timestamp is overwritten with current time.  Even with a 32K buffer, this
  967.     does not seem to occur with larger files.  UnZip output is now unbuffered,
  968.     but if it were not, could still avoid problem by adding "fflush(outfile)"
  969.     just before setftime() call.  Weird, huh?
  970.   ---------------------------------------------------------------------------*/
  971.  
  972. #ifdef __TURBOC__
  973.     td.zt.ztime = lrec.last_mod_file_time;
  974.     td.zt.zdate = lrec.last_mod_file_date;
  975.     setftime(fileno(outfile), &td.ft);
  976. #else
  977.     _dos_setftime(fileno(outfile), lrec.last_mod_file_date,
  978.                                    lrec.last_mod_file_time);
  979. #endif
  980.  
  981. /*---------------------------------------------------------------------------
  982.     And finally we can close the file...at least everybody agrees on how to
  983.     do *this*.  I think...  Oh yeah, also change the mode according to the
  984.     stored file attributes, since we didn't do that when we opened the dude.
  985.   ---------------------------------------------------------------------------*/
  986.  
  987.     fclose(outfile);
  988.  
  989. #ifdef __TURBOC__
  990.     if (_chmod(filename, 1, pInfo->file_attr) != pInfo->file_attr)
  991.         fprintf(stderr, "\nwarning:  file attributes may not be correct\n");
  992. #else
  993.     _dos_setfileattr(filename, pInfo->file_attr);
  994. #endif
  995.  
  996. } /* end function close_outfile() */
  997.  
  998.  
  999.  
  1000.  
  1001.  
  1002. /*************************/
  1003. /* Function dateformat() */
  1004. /*************************/
  1005.  
  1006. int dateformat()
  1007. {
  1008.  
  1009. /*---------------------------------------------------------------------------
  1010.     For those operating systems which support it, this function returns a
  1011.     value which tells how national convention says that numeric dates are
  1012.     displayed.  Return values are DF_YMD, DF_DMY and DF_MDY (the meanings
  1013.     should be fairly obvious).
  1014.   ---------------------------------------------------------------------------*/
  1015.  
  1016. #if (!defined(MSWIN) && !defined(__GO32__) && !defined(__EMX__))
  1017.     unsigned short _CountryInfo[18];
  1018.     unsigned short far *CountryInfo = _CountryInfo;
  1019.     struct SREGS sregs;
  1020.     union REGS regs;
  1021.  
  1022.     sregs.ds  = FP_SEG(CountryInfo);
  1023.     regs.x.dx = FP_OFF(CountryInfo);
  1024.     regs.x.ax = 0x3800;
  1025.     int86x(0x21, ®s, ®s, &sregs);
  1026.  
  1027.     switch(CountryInfo[0]) {
  1028.         case 0:
  1029.             return DF_MDY;
  1030.         case 1:
  1031.             return DF_DMY;
  1032.         case 2:
  1033.             return DF_YMD;
  1034.     }
  1035. #endif /* !MSWIN  && !__GO32__ && !__EMX__ */
  1036.  
  1037.     return DF_MDY;   /* default for systems without locale info */
  1038.  
  1039. } /* end function dateformat() */
  1040.  
  1041.  
  1042.  
  1043.  
  1044.  
  1045. #if (defined(__GO32__) || defined(__EMX__))
  1046.  
  1047. int volatile _doserrno;
  1048.  
  1049. void _dos_setftime(int fd, ush dosdate, ush dostime)
  1050. {
  1051.     asm("movl %0, %%ebx": : "g" (fd));
  1052.     asm("movl %0, %%ecx": : "g" (dostime));
  1053.     asm("movl %0, %%edx": : "g" (dosdate));
  1054.     asm("movl $0x5701, %eax");
  1055.     asm("int $0x21": : : "%eax", "%ebx", "%ecx", "%edx", "%esi", "%edi");
  1056. }
  1057.  
  1058. void _dos_setfileattr(char *name, int attr)
  1059. {
  1060.     asm("movl %0, %%edx": : "g" (name));
  1061.     asm("movl %0, %%ecx": : "g" (attr));
  1062.     asm("movl $0x4301, %eax");
  1063.     asm("int $0x21": : : "%eax", "%ebx", "%ecx", "%edx", "%esi", "%edi");
  1064. }
  1065.  
  1066. void _dos_getdrive(unsigned *d)
  1067. {
  1068.     asm("movl $0x1900, %eax");
  1069.     asm("int $0x21": : : "%eax", "%ebx", "%ecx", "%edx", "%esi", "%edi");
  1070.     asm("xorb %ah, %ah");
  1071.     asm("incb %al");
  1072.     asm("movl %%eax, %0": "=a" (*d));
  1073. }
  1074.  
  1075. unsigned _dos_creat(char *path, unsigned attr, int *fd)
  1076. {
  1077.     asm("movl $0x3c00, %eax");
  1078.     asm("movl %0, %%edx": :"g" (path));
  1079.     asm("movl %0, %%ecx": :"g" (attr));
  1080.     asm("int $0x21": : : "%eax", "%ebx", "%ecx", "%edx", "%esi", "%edi");
  1081.     asm("movl %%eax, %0": "=a" (*fd));
  1082.     _doserrno = 0;
  1083.     asm("jnc 1f");
  1084.     _doserrno = *fd;
  1085.     switch (_doserrno) {
  1086.     case 3:
  1087.            errno = ENOENT;
  1088.            break;
  1089.     case 4:
  1090.            errno = EMFILE;
  1091.            break;
  1092.     case 5:
  1093.            errno = EACCES;
  1094.            break;
  1095.     }
  1096.     asm("1:");
  1097.     return _doserrno;
  1098. }
  1099.  
  1100. unsigned _dos_close(int fd)
  1101. {
  1102.     asm("movl %0, %%ebx": : "g" (fd));
  1103.     asm("movl $0x3e00, %eax");
  1104.     asm("int $0x21": : : "%eax", "%ebx", "%ecx", "%edx", "%esi", "%edi");
  1105.     _doserrno = 0;
  1106.     asm("jnc 1f");
  1107.     asm ("movl %%eax, %0": "=m" (_doserrno));
  1108.     if (_doserrno == 6) {
  1109.           errno = EBADF;
  1110.     }
  1111.     asm("1:");
  1112.     return _doserrno;
  1113. }
  1114.  
  1115. static int volumelabel(char *name)
  1116. {
  1117.     int fd;
  1118.  
  1119.     return _dos_creat(name, FA_LABEL, &fd) ? fd : _dos_close(fd);
  1120. }
  1121.  
  1122. #endif /* __GO32__ || __EMX__ */
  1123.