home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / thesrc15.zip / nonansi.c < prev    next >
C/C++ Source or Header  |  1993-11-17  |  22KB  |  735 lines

  1. /***********************************************************************/
  2. /* NONANSI.C -                                                         */
  3. /* This file contains all calls to non-ansi conforming routines.       */
  4. /***********************************************************************/
  5. /*
  6.  * THE - The Hessling Editor. A text editor similar to VM/CMS xedit.
  7.  * Copyright (C) 1991-1993 Mark Hessling
  8.  *
  9.  * This program is free software; you can redistribute it and/or
  10.  * modify it under the terms of the GNU General Public License as
  11.  * published by the Free Software Foundation; either version 2 of
  12.  * the License, or any later version.
  13.  *
  14.  * This program is distributed in the hope that it will be useful,
  15.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17.  * General Public License for more details.
  18.  *
  19.  * You should have received a copy of the GNU General Public License
  20.  * along with this program; if not, write to:
  21.  *
  22.  *    The Free Software Foundation, Inc.
  23.  *    675 Mass Ave,
  24.  *    Cambridge, MA 02139 USA.
  25.  *
  26.  *
  27.  * If you make modifications to this software that you feel increases
  28.  * it usefulness for the rest of the community, please email the
  29.  * changes, enhancements, bug fixes as well as any and all ideas to me.
  30.  * This software is going to be maintained and enhanced as deemed
  31.  * necessary by the community.
  32.  *
  33.  * Mark Hessling                     email: M.Hessling@gu.edu.au
  34.  * 36 David Road                     Phone: +61 7 849 7731
  35.  * Holland Park                      Fax:   +61 7 875 5314
  36.  * QLD 4121
  37.  * Australia
  38.  */
  39.  
  40. /*
  41. $Header: C:\THE\RCS\nonansi.c 1.4 1993/09/01 16:26:46 MH Interim MH $
  42. */
  43.  
  44. #include <stdio.h>
  45.  
  46. #include <errno.h>
  47.  
  48. #include "the.h"
  49. #include "proto.h"
  50.  
  51. #ifdef UNIX
  52. #include <pwd.h>
  53. #endif
  54.  
  55. /*#define DEBUG 1*/
  56.  
  57. #ifdef DOS
  58. #  include <dos.h>
  59. #  ifndef GO32
  60. #    include <direct.h>
  61. #  endif
  62. #endif
  63.  
  64. #ifdef OS2
  65. #  ifndef EMX
  66. #    include <direct.h>
  67. #  endif
  68. #  include <io.h>
  69. #  ifndef S_IFMT
  70. #    define S_IFMT 0xF000
  71. #  endif
  72. #endif
  73.  
  74. /*-------------------------- external data ----------------------------*/
  75. extern char curr_path[MAX_FILE_NAME+1] ;
  76. extern char sp_path[MAX_FILE_NAME+1] ;
  77. extern char sp_fname[MAX_FILE_NAME+1] ;
  78. extern char dir_path[MAX_FILE_NAME+1] ;   /* for dir and ls commands */
  79. extern char file_disposition;
  80. extern struct stat stat_buf;
  81. /***********************************************************************/
  82. #ifdef PROTO
  83. int file_readable(char *filename)
  84. #else
  85. int file_readable(filename)
  86. char *filename;
  87. #endif
  88. /***********************************************************************/
  89. {
  90. /*--------------------------- local data ------------------------------*/
  91. /*--------------------------- processing ------------------------------*/
  92. #ifdef TRACE
  93.  trace_function("nonansi.c :file_readable");
  94. #endif
  95.  if (!file_exists(filename))
  96.    {
  97. #ifdef TRACE
  98.     trace_return();
  99. #endif
  100.     return(YES);
  101.    }
  102.  if (access(filename,R_OK) == (-1))
  103.    {
  104. #ifdef TRACE
  105.     trace_return();
  106. #endif
  107.     return(NO);
  108.    }
  109. #ifdef TRACE
  110.     trace_return();
  111. #endif
  112.  return(YES);
  113. }
  114. /***********************************************************************/
  115. #ifdef PROTO
  116. int file_writable(char *filename)
  117. #else
  118. int file_writable(filename)
  119. char *filename;
  120. #endif
  121. /***********************************************************************/
  122. {
  123. /*--------------------------- local data ------------------------------*/
  124. /*--------------------------- processing ------------------------------*/
  125. #ifdef TRACE
  126.  trace_function("nonansi.c :file_writable");
  127. #endif
  128.  if (!file_exists(filename))
  129.    {
  130. #ifdef TRACE
  131.     trace_return();
  132. #endif
  133.     return(YES);
  134.    }
  135.  if (access(filename,W_OK) == (-1))
  136.    {
  137. #ifdef TRACE
  138.     trace_return();
  139. #endif
  140.     return(NO);
  141.    }
  142. #ifdef TRACE
  143.  trace_return();
  144. #endif
  145.  return(YES);
  146. }
  147. /***********************************************************************/
  148. #ifdef PROTO
  149. int file_exists(char *filename)
  150. #else
  151. int file_exists(filename)
  152. char *filename;
  153. #endif
  154. /***********************************************************************/
  155. {
  156. /*--------------------------- local data ------------------------------*/
  157. /*--------------------------- processing ------------------------------*/
  158. #ifdef TRACE
  159.  trace_function("nonansi.c :file_exists");
  160. #endif
  161.  if (access(filename,F_OK) == (-1))
  162.    {
  163. #ifdef TRACE
  164.     trace_return();
  165. #endif
  166.     return(NO);
  167.    }
  168. #ifdef TRACE
  169.  trace_return();
  170. #endif
  171.  return(YES);
  172. }
  173. /***********************************************************************/
  174. #ifdef PROTO
  175. int remove_file(char *filename)
  176. #else
  177. int remove_file(filename)
  178. char *filename;
  179. #endif
  180. /***********************************************************************/
  181. {
  182. /*--------------------------- local data ------------------------------*/
  183. int anerror;
  184. /*--------------------------- processing ------------------------------*/
  185. #ifdef TRACE
  186.  trace_function("nonansi.c :remove_file");
  187. #endif
  188. #ifdef VMS
  189.  if (delete(filename) == (-1))
  190. #else
  191.  if (unlink(filename) == (-1))
  192. #endif
  193.    {
  194.     anerror = errno;
  195. #ifdef TRACE
  196.     trace_return();
  197. #endif
  198.     return(RC_ACCESS_DENIED);
  199.    }
  200.     anerror = errno;
  201. #ifdef TRACE
  202.  trace_return();
  203. #endif
  204.  return(RC_OK);
  205. }
  206. #if defined(DOS) || defined(OS2)
  207. /***********************************************************************/
  208. #ifdef PROTO
  209. short splitpath(char *filename)
  210. #else
  211. short splitpath(filename)
  212. char *filename;
  213. #endif
  214. /***********************************************************************/
  215. {
  216. /*--------------------------- local data ------------------------------*/
  217.  short len;
  218.  char work_filename[MAX_FILE_NAME+1] ;
  219.  char current_dir[MAX_FILE_NAME+1] ;
  220. #if defined(DOS)
  221.  int new_dos_disk=0,current_dos_disk=0;        /* 1 - A,2 - B... */
  222.  int temp_disk=0;
  223. #endif
  224. #ifdef OS2
  225.  ULONG logical_os2_drives=0L;
  226. #  ifdef __32BIT__
  227.  ULONG new_dos_disk=0L,current_dos_disk=0L,temp_disk=0L;
  228. #  else
  229.  USHORT new_dos_disk=0,current_dos_disk=0,temp_disk=0;
  230. #  endif
  231. #endif
  232. /*--------------------------- processing ------------------------------*/
  233. #ifdef TRACE
  234.  trace_function("nonansi.c :splitpath");
  235. #endif
  236.  strcpy(sp_path,"");
  237.  strcpy(sp_fname,"");
  238.  strcpy(work_filename,filename);
  239. /*---------------------------------------------------------------------*/
  240. /* If the supplied filename is empty, set the path = cwd and filename  */
  241. /* equal to blank.                                                     */
  242. /*---------------------------------------------------------------------*/
  243.  if (strcmp(filename,"") == 0)
  244.    {
  245. #if defined(EMX)
  246.     _getcwd2(sp_path,MAX_FILE_NAME);
  247. #else
  248.     getcwd(sp_path,MAX_FILE_NAME);
  249. #endif
  250.     strcpy(sp_fname,"");
  251.    }
  252. /*---------------------------------------------------------------------*/
  253. /* For DOS and OS/2, get current drive.                                */
  254. /*---------------------------------------------------------------------*/
  255. #ifdef DOS
  256. #  if defined(TC) || defined(GO32)
  257.  current_dos_disk = getdisk() + 1;
  258. #  else
  259.  _dos_getdrive(¤t_dos_disk);
  260. #  endif
  261. #endif
  262. #ifdef OS2
  263.  DosQueryCurrentDisk(¤t_dos_disk,&logical_os2_drives);
  264. #endif
  265.  
  266.  new_dos_disk = current_dos_disk;
  267. /*---------------------------------------------------------------------*/
  268. /* For DOS and OS/2, if a drive specified determine the drive number.  */
  269. /*---------------------------------------------------------------------*/
  270.  if (*(filename+1) == ':')/* we assume this means a drive secification */
  271.     new_dos_disk = (toupper(*(filename)) - 'A') + 1;
  272. /*---------------------------------------------------------------------*/
  273. /* For DOS and OS/2, change to the specified disk (if supplied and     */
  274. /* different). Validate the drive number.                              */
  275. /*---------------------------------------------------------------------*/
  276.  if (new_dos_disk != current_dos_disk)
  277.    {
  278. #ifdef DOS
  279. #  if defined(TC) || defined(GO32)
  280.     setdisk((int)(new_dos_disk-1));
  281.     temp_disk = getdisk()+1;
  282. #  else
  283.     _dos_setdrive(new_dos_disk,&temp_disk);
  284.     _dos_getdrive(&temp_disk);
  285. #  endif
  286. #endif
  287. #ifdef OS2
  288.     DosSetDefaultDisk(new_dos_disk);
  289.     DosQueryCurrentDisk(&temp_disk,&logical_os2_drives);
  290. #endif
  291.     if (temp_disk != new_dos_disk)  /* invalid drive */
  292.       {
  293. #ifdef TRACE
  294.        trace_return();
  295. #endif
  296.        return (RC_BAD_DRIVE);
  297.       }
  298.    }
  299. /*---------------------------------------------------------------------*/
  300. /* Save the current working directory on the specified drive, or the   */
  301. /* current drive if not specified.                                     */
  302. /*---------------------------------------------------------------------*/
  303. #if defined(EMX)
  304.  _getcwd2(current_dir,MAX_FILE_NAME);
  305. #else
  306.  getcwd(current_dir,MAX_FILE_NAME);
  307. #endif
  308. /*---------------------------------------------------------------------*/
  309. /* If the work_filename contains a drive specifier, special handling is*/
  310. /* needed.                                                             */
  311. /*---------------------------------------------------------------------*/
  312.  switch(strlen(filename))
  313.    {
  314.     case 1:
  315.          break;
  316. /*---------------------------------------------------------------------*/
  317. /* If the filename consists only of a drive specifier, copy the current*/
  318. /* directory for the now new drive into work_filename.                 */
  319. /*---------------------------------------------------------------------*/
  320.     case 2:
  321.          if (*(filename+1) == ':')
  322.             strcpy(work_filename,current_dir);
  323.          break;
  324.     default:
  325.          if (*(filename+1) == ':'
  326.          &&  *(filename+2) != ISLASH)
  327.            {
  328.             strcpy(work_filename,current_dir);
  329.             if (current_dir[strlen(current_dir)-1] != ISLASH)
  330.                strcat(work_filename,ISTR_SLASH);
  331.             strcat(work_filename,filename+2);
  332.            }
  333.          break;
  334.    }
  335. /*---------------------------------------------------------------------*/
  336. /* First determine if the supplied filename is a directory.            */
  337. /*---------------------------------------------------------------------*/
  338.  if (chdir(work_filename) == 0)  /* valid directory */
  339.    {
  340. #if defined(EMX)
  341.     _getcwd2(sp_path,MAX_FILE_NAME);
  342. #else
  343.     getcwd(sp_path,MAX_FILE_NAME);
  344. #endif
  345.     strcpy(sp_fname,"");
  346.    }
  347.  else          /* here if the file is not a directory */
  348.    {
  349.     len = strzreveq(work_filename,ISLASH);
  350.     switch(len)
  351.       {
  352.        case (-1):
  353. #if defined(EMX)
  354.             _getcwd2(sp_path,MAX_FILE_NAME);
  355. #else
  356.             getcwd(sp_path,MAX_FILE_NAME);
  357. #endif
  358.             strcpy(sp_fname,work_filename);
  359.             break;
  360.        case 0:
  361.             strcpy(sp_path,work_filename);
  362.             sp_path[1] = '\0';
  363.             strcpy(sp_fname,work_filename+1+len);
  364.             break;
  365.       default:
  366.             strcpy(sp_path,work_filename);
  367.             sp_path[len] = '\0';
  368.             strcpy(sp_fname,work_filename+1+len);
  369.             break;
  370.      }
  371.    }
  372.  if (strlen(sp_path) == 2
  373.  && sp_path[1] == ':')
  374.     strcat(sp_path,ISTR_SLASH);
  375. /*---------------------------------------------------------------------*/
  376. /* Change directory to the supplied path, if possible and store the    */
  377. /* expanded path.                                                      */
  378. /* If an error, restore the current path.                              */
  379. /*---------------------------------------------------------------------*/
  380.  if (chdir(sp_path) != 0)
  381.    {
  382.     if (new_dos_disk != current_dos_disk)
  383.       {
  384.        chdir(current_dir);
  385. #ifdef DOS
  386. #  if defined(TC) || defined(GO32)
  387.        setdisk((int)(current_dos_disk-1));
  388. #  else
  389.        _dos_setdrive(current_dos_disk,&temp_disk);
  390. #  endif
  391. #endif
  392. #ifdef OS2
  393.        DosSetDefaultDisk(new_dos_disk);
  394. #endif
  395.       }
  396.     chdir(curr_path);
  397. #ifdef TRACE
  398.     trace_return();
  399. #endif
  400.     return(RC_FILE_NOT_FOUND);
  401.    }
  402. /*---------------------------------------------------------------------*/
  403. /* We are now in a valid directory, get the fully qualified directory  */
  404. /* name.                                                               */
  405. /*---------------------------------------------------------------------*/
  406. #if defined(EMX)
  407.  _getcwd2(sp_path,MAX_FILE_NAME);
  408. #else
  409.  getcwd(sp_path,MAX_FILE_NAME);
  410. #endif
  411. /*---------------------------------------------------------------------*/
  412. /* For DOS or OS/2, change back to the current directory of the now    */
  413. /* current disk and then change back to the original disk.             */
  414. /*---------------------------------------------------------------------*/
  415.  if (new_dos_disk != current_dos_disk)
  416.    {
  417.     if (chdir(current_dir) != 0)
  418.       {
  419. #ifdef TRACE
  420.        trace_return();
  421. #endif
  422.        return(RC_FILE_NOT_FOUND);
  423.       }
  424. #ifdef DOS
  425. #  if defined(TC) || defined(GO32)
  426.     setdisk((int)(current_dos_disk-1));
  427. #  else
  428.     _dos_setdrive(current_dos_disk,&temp_disk);
  429. #  endif
  430. #endif
  431. #ifdef OS2
  432.     DosSetDefaultDisk(current_dos_disk);
  433. #endif
  434.    }
  435.  
  436.  chdir(curr_path);
  437. /*---------------------------------------------------------------------*/
  438. /* Append the OS directory character to the path if it doesn't already */
  439. /* end in the character.                                               */
  440. /*---------------------------------------------------------------------*/
  441. #ifndef VMS
  442.  len = strlen(sp_path);
  443.  if (len > 0)
  444.     if (sp_path[len-1] != ISLASH)
  445.        strcat(sp_path,(char *)ISTR_SLASH);
  446. #endif
  447. #ifdef TRACE
  448.  trace_return();
  449. #endif
  450.  return(RC_OK);
  451. }
  452. #else
  453. /***********************************************************************/
  454. #ifdef PROTO
  455. short splitpath(char *filename)
  456. #else
  457. short splitpath(filename)
  458. char *filename;
  459. #endif
  460. /***********************************************************************/
  461. {
  462. /*--------------------------- local data ------------------------------*/
  463.  short len;
  464.  char work_filename[MAX_FILE_NAME+1] ;
  465. /*--------------------------- processing ------------------------------*/
  466. #ifdef TRACE
  467.  trace_function("nonansi.c :splitpath");
  468. #endif
  469.  strcpy(sp_path,"");
  470.  strcpy(sp_fname,"");
  471.  strcpy(work_filename,filename);
  472. /*---------------------------------------------------------------------*/
  473. /* If the supplied filename is empty, set the path = cwd and filename  */
  474. /* equal to blank.                                                     */
  475. /*---------------------------------------------------------------------*/
  476.  if (strcmp(filename,"") == 0)
  477.    {
  478.     getcwd(sp_path,MAX_FILE_NAME);
  479.     strcpy(sp_fname,"");
  480.    }
  481. /*---------------------------------------------------------------------*/
  482. /* Check if the first character is tilde; translate HOME env variable  */
  483. /* if there is one. Obviously only applicable to UNIX.                 */
  484. /*---------------------------------------------------------------------*/
  485.  if (*(work_filename) == '~')
  486.    {
  487.     if (*(work_filename+1) == ISLASH)
  488.       {
  489.        strcpy(work_filename,(char *)getenv("HOME"));
  490.        strcat(work_filename,(filename+1));
  491.       }
  492.     else
  493.       {
  494.        struct passwd *pwd;
  495.  
  496.        strcpy(sp_path,filename+1);
  497.        if ((len = strzeq(sp_path,ISLASH)) != (-1))
  498.           sp_path[len] = '\0';
  499.        if ((pwd = getpwnam(sp_path)) == NULL)
  500.           return(RC_BAD_FILEID);
  501.        strcpy(work_filename,pwd->pw_dir);
  502.        if (len != (-1))
  503.           strcat(work_filename,(filename+1+len));
  504.       }
  505.    }
  506. /*---------------------------------------------------------------------*/
  507. /* First determine if the supplied filename is a directory.            */
  508. /*---------------------------------------------------------------------*/
  509.  if ((stat(work_filename,&stat_buf) == 0)
  510.  &&  (stat_buf.st_mode & S_IFMT) == S_IFDIR)
  511.    {
  512.     strcpy(sp_path,work_filename);
  513.     strcpy(sp_fname,"");
  514.    }
  515.  else          /* here if the file doesn't exist or is not a directory */
  516.    {
  517.     len = strzreveq(work_filename,ISLASH);
  518.     switch(len)
  519.       {
  520.        case (-1):
  521.             getcwd(sp_path,MAX_FILE_NAME);
  522.             strcpy(sp_fname,work_filename);
  523.             break;
  524.        case 0:
  525.             strcpy(sp_path,work_filename);
  526.             sp_path[1] = '\0';
  527.             strcpy(sp_fname,work_filename+1+len);
  528.             break;
  529.       default:
  530.             strcpy(sp_path,work_filename);
  531.             sp_path[len] = '\0';
  532.             strcpy(sp_fname,work_filename+1+len);
  533.             break;
  534.      }
  535.    }
  536. /*---------------------------------------------------------------------*/
  537. /* Change directory to the supplied path, if possible and store the    */
  538. /* expanded path.                                                      */
  539. /* If an error, restore the current path.                              */
  540. /*---------------------------------------------------------------------*/
  541.  if (chdir(sp_path) != 0)
  542.    {
  543.     chdir(curr_path);
  544. #ifdef TRACE
  545.     trace_return();
  546. #endif
  547.     return(RC_FILE_NOT_FOUND);
  548.    }
  549.  getcwd(sp_path,MAX_FILE_NAME);
  550.  chdir(curr_path);
  551. /*---------------------------------------------------------------------*/
  552. /* Append the OS directory character to the path if it doesn't already */
  553. /* end in the character.                                               */
  554. /*---------------------------------------------------------------------*/
  555. #ifndef VMS
  556.  len = strlen(sp_path);
  557.  if (len > 0)
  558.     if (sp_path[len-1] != ISLASH)
  559.        strcat(sp_path,(char *)ISTR_SLASH);
  560. #endif
  561. #ifdef TRACE
  562.  trace_return();
  563. #endif
  564.  return(RC_OK);
  565. }
  566. #endif
  567.  
  568. #ifdef NO_RENAME
  569. /***********************************************************************/
  570. #ifdef PROTO
  571. int rename(char *path1,char *path2)
  572. #else
  573. int rename(path1,path2)
  574. char *path1;
  575. char *path2;
  576. #endif
  577. /***********************************************************************/
  578. /* Function  : Emulate missing rename() function missing from SystemV  */
  579. /* Parameters: path1    - old filename                                 */
  580. /*             path2    - new_filename                                 */
  581. /* Return    : 0 on success, -1 on error                               */
  582. /***********************************************************************/
  583. {
  584. #ifdef TRACE
  585.  trace_function("nonansi.c :rename");
  586. #endif
  587.   if (link(path1,path2) != 0)
  588.     {
  589. #ifdef TRACE
  590.      trace_return();
  591. #endif
  592.      return(-1);
  593.     }
  594.   if (unlink(path1) != 0)
  595.     {
  596. #ifdef TRACE
  597.      trace_return();
  598. #endif
  599.      return(-1);
  600.     }
  601. #ifdef TRACE
  602.  trace_return();
  603. #endif
  604.  return(0);
  605. }
  606. #endif
  607.  
  608. #ifdef OS2
  609.  
  610. #  ifdef __32BIT__
  611. #  define FSQBUFFERSIZE 64
  612.  
  613. /***********************************************************************/
  614. bool LongFileNames(char *path)
  615. /***********************************************************************/
  616. /* Function  : Determine if file system allows long file names. (HPFS) */
  617. /*             This is the 32-bit version.                             */
  618. /* Parameters: path     - directory path                               */
  619. /* Return    : 1 if file system is HPFS                                */
  620. /***********************************************************************/
  621. {
  622. /*--------------------------- local data ------------------------------*/
  623.     ULONG nDrive;
  624.     ULONG lMap;
  625.     char buffer[FSQBUFFERSIZE];
  626.     FSQBUFFER2 *bData = (FSQBUFFER2 *) buffer;
  627.     char bName[3];
  628.     ULONG bDataLen;
  629. /*--------------------------- processing ------------------------------*/
  630. #ifdef TRACE
  631.  trace_function("file.c:    LongFileNames");
  632. #endif
  633.  if ((strlen (path) > 0) && path [1] == ':')
  634.     bName[0] = path[0];
  635.  else 
  636.    {
  637.     DosQueryCurrentDisk(&nDrive, &lMap);
  638.     bName[0] = (char) (nDrive + 'A' - 1);
  639.    }
  640.  bName[1] = ':';
  641.  bName[2] = 0;
  642.  bDataLen = FSQBUFFERSIZE;
  643.  DosQueryFSAttach(bName, 0, FSAIL_QUERYNAME, bData, &bDataLen);
  644.  return(strcmp(bData->szFSDName + bData->cbName, "HPFS") == 0);
  645. }
  646. #  else
  647.  
  648. /***********************************************************************/
  649. bool LongFileNames(char *path)
  650. /***********************************************************************/
  651. /* Function  : Determine if file system allows long filenames. (HPFS)  */
  652. /*             This is the 16-bit version.                             */
  653. /* Parameters: path     - directory path                               */
  654. /* Return    : 1 if file system is HPFS                                */
  655. /***********************************************************************/
  656. {
  657. typedef struct _FSNAME {
  658.         USHORT cbName;
  659.         UCHAR  szName[1];
  660. } FSNAME;
  661. typedef struct _FSQINFO {
  662.         USHORT iType;
  663.         FSNAME Name;
  664.         UCHAR  rgFSAData[59];
  665. } FSQINFO;
  666. typedef FSQINFO FAR *PFSQINFO;
  667. /*--------------------------- local data ------------------------------*/
  668.  USHORT nDrive,cbData;
  669.  ULONG lMap;
  670.  FSQINFO bData;
  671.  BYTE bName[3];
  672.  FSNAME *pFSName;
  673. /*--------------------------- processing ------------------------------*/
  674. #ifdef TRACE
  675.  trace_function("file.c:    LongFileNames");
  676. #endif
  677.  if ((strlen(path) > 0) && path[1] == ':')
  678.     bName[0] = path[0];
  679.  else
  680.    {
  681.     DosQueryCurrentDisk(&nDrive, &lMap);
  682.     bName[0] = (char)(nDrive + '@');
  683.    }
  684.  bName[1] = ':';
  685.  bName[2] = 0;
  686.  cbData = sizeof(bData);
  687.  DosQFSAttach((PSZ)bName,0,1,(PBYTE)&bData,&cbData,0L);
  688.  pFSName = &bData.Name;
  689.  (char *)pFSName += pFSName->cbName + sizeof(pFSName->cbName)+1;
  690.  return(strcmp((char *)&(pFSName->szName[0]),"HPFS") == 0);
  691. }
  692. #  endif
  693. #endif
  694.  
  695. #ifdef GO32
  696. /***********************************************************************/
  697. #ifdef PROTO
  698. int getdisk(void)
  699. #else
  700. int getdisk()
  701. #endif
  702. /***********************************************************************/
  703. /* Function  : Determine the drive letter for the current disk.        */
  704. /* Parameters: nil                                                     */
  705. /* Return    : 0 for drive A:, 1 for drive B:, etc...                  */
  706. /***********************************************************************/
  707. {
  708. /*--------------------------- local data ------------------------------*/
  709. /*--------------------------- processing ------------------------------*/
  710.  regs.h.ah = 0x19;
  711.  int86(0x21, ®s, ®s);
  712.  return ((int) regs.h.al);
  713. }
  714. /***********************************************************************/
  715. #ifdef PROTO
  716. int setdisk(int drive)
  717. #else
  718. int setdisk(drive)
  719. int drive;
  720. #endif
  721. /***********************************************************************/
  722. /* Function  : Change the current drive to that specified.             */
  723. /* Parameters: 0 for drive A:, 2 for drive B:, etc...                  */
  724. /* Return    : number of drives present                                */
  725. /***********************************************************************/
  726. {
  727. /*--------------------------- local data ------------------------------*/
  728. /*--------------------------- processing ------------------------------*/
  729.  regs.h.ah = 0x0e;
  730.  regs.h.dl = (char)drive;
  731.  int86(0x21, ®s, ®s);
  732.  return ((int) regs.h.al);
  733. }
  734. #endif
  735.