home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / lpr32.zip / text.tmp < prev   
Text File  |  2001-03-06  |  3KB  |  54 lines

  1.  
  2.  This example obtains the information of the CONFIG.SYS file. 
  3.  
  4.   #define INCL_DOSFILEMGR   /* File Manager values */
  5.   #define INCL_DOSERRORS    /* DOS error values    */
  6.   #include <os2.h>
  7.   #include <stdio.h>
  8.  
  9.   int main(VOID) {
  10.   UCHAR        uchFileName[80] = "C:\\CONFIG.SYS";  /* File to manipulate    */
  11.   FILESTATUS3  fsts3ConfigInfo = {{0}};       /* Buffer for file information */
  12.   ULONG        ulBufSize     = sizeof(FILESTATUS3);  /* Size of above buffer */
  13.   HFILE        hfConfig      = 0;             /* Handle for Config file      */
  14.   ULONG        ulOpenAction  = 0;             /* Action taken by DosOpen     */
  15.   APIRET       rc            = NO_ERROR;      /* Return code                 */
  16.  
  17.    rc = DosOpen(uchFileName,                 /* File to open (path and name) */
  18.                 &hfConfig,                /* File handle returned         */
  19.                 &ulOpenAction,               /* Action taken by DosOpen      */
  20.                 0L,0L,        /* Primary allocation and attributes (ignored) */
  21.                 OPEN_ACTION_FAIL_IF_NEW |
  22.                 OPEN_ACTION_OPEN_IF_EXISTS,  /* Open an existing file only   */
  23.                 OPEN_FLAGS_NOINHERIT | OPEN_ACCESS_READONLY |
  24.                 OPEN_SHARE_DENYNONE,         /* Read access only             */
  25.                 0L);                         /* Extended attributes (ignored)*/
  26.  
  27.      if (rc != NO_ERROR) {
  28.          printf("DosOpen error: return code = %u\n", rc);
  29.          return 1;
  30.      }
  31.  
  32.      rc = DosQueryFileInfo(hfConfig,   /* Handle of file                  */
  33.                            FIL_STANDARD,  /* Request standard (Level 1) info */
  34.                            &fsts3ConfigInfo, /* Buffer for file information  */
  35.                            ulBufSize);    /* Size of buffer                  */
  36.      if (rc != NO_ERROR) {
  37.          printf("DosQueryFileInfo error: return code = %u\n", rc);
  38.          return 1;
  39.      }
  40.  
  41.      rc = DosClose(hfConfig);      /* Close the file  (check RC in real life) */
  42.      printf("%s ---  File size: %u bytes\n",uchFileName, fsts3ConfigInfo.cbFile);
  43.      printf("Last updated: %d/%d/%d; %d:%2.2d\n",
  44.              fsts3ConfigInfo.fdateLastWrite.month,        /* Month            */
  45.              fsts3ConfigInfo.fdateLastWrite.day,          /* Day              */
  46.              (fsts3ConfigInfo.fdateLastWrite.year+1980L), /* Years since 1980 */
  47.              fsts3ConfigInfo.ftimeLastWrite.hours,        /* Hours            */
  48.              fsts3ConfigInfo.ftimeLastWrite.minutes);     /* Minutes          */
  49.  
  50.    return NO_ERROR;
  51.  }
  52.  
  53.  
  54.