home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c017 / 36.ddi / DBTOC.ZIP / FILEIO.ASM < prev    next >
Encoding:
Assembly Source File  |  1987-10-29  |  11.1 KB  |  435 lines

  1. include PROGSEG.H
  2.  
  3. ;----------------------------------------------------------------------------
  4. ;   c_reate(filename,attr) - creates a file
  5. ;        char *filename - ptr to filename
  6. ;        int  attr      - attributes to use for file
  7. ;
  8. ;   returns file handle or        -1 - error
  9. ;
  10. ;----------------------------------------------------------------------------
  11. public   c_reate
  12. c_reate  proc near
  13.  
  14.          push bp
  15.          mov  bp,sp
  16.  
  17.          mov  ax,03c00h
  18.          mov  dx,4[bp]       ; get the file name
  19.          mov  cx,6[bp]       ;get attributes of new file
  20.  
  21.          int  21h            ; call dos
  22.  
  23.          jnc  createx
  24.          mov  ax,-1
  25.  
  26. createx:
  27.          mov  sp,bp
  28.          pop  bp
  29.          ret
  30.  
  31. c_reate  endp
  32.  
  33. ;-----------------------------------------------------------------------------
  34. ;
  35. ;   o_pen(filename,acc_code)
  36. ;        char *filename      - file name string
  37. ;        int  acc_code       - 0 - file opened for reading
  38. ;                              1 - file opened for writing
  39. ;                              2 - file opened for read/write
  40. ;   returns - file handle or error code ( see error table)
  41. ;----------------------------------------------------------------------------
  42.  
  43. public   o_pen 
  44.  
  45. o_pen    proc near
  46.  
  47.          push bp
  48.          mov  bp,sp
  49.  
  50.          mov  dx,[bp+4]             ;offset, small model ds points already
  51.          mov  al,[bp+6]             ;access code r/w/w-r
  52.          mov  ah,03dh               ; open a file 
  53.          int  21h
  54.  
  55.          jnc  openex
  56.          mov  ax,-1
  57.  
  58. openex:  mov  sp,bp
  59.          pop  bp
  60.          ret
  61.  
  62. o_pen    endp
  63.  
  64. ;-----------------------------------------------------------------------------
  65. ;   C_LOSE(fh) - closes a valid file handle
  66. ;        int  fh   - file handle
  67. ;
  68. ;   returns - 0 - successfull, -1 - invalid file handle
  69. ;-----------------------------------------------------------------------------
  70.  
  71. public   c_lose
  72. c_lose   proc near
  73.  
  74.          push bp
  75.          mov  bp,sp
  76.  
  77.          mov  bx,4[bp]       ; get file handle
  78.          mov  ah,03eh        ; service to close a file handle
  79.  
  80.          int  21h
  81.          mov  ax,00
  82.  
  83.          jnc  closex
  84.  
  85.          mov  ax,-1          ; tell prog that error occurred
  86.  
  87. closex:  mov  sp,bp
  88.          pop  bp
  89.          ret
  90.  
  91. c_lose   endp
  92. ;---------------------------------------------------------------------------
  93. ;   _DEL(filename) - deletes a file from the directory
  94. ;
  95. ;   char *filename - name of file to delete
  96. ;
  97. ;   returns   0 - success    or error code: 2 - file not found
  98. ;                                           5 - access denied
  99. ;----------------------------------------------------------------------------
  100. public   _del
  101. _del     proc near
  102.  
  103.          push bp
  104.          mov  bp,sp
  105.  
  106.          mov  dx,4[bp]
  107.          mov  ax,4100h
  108.          int  21h
  109.  
  110.          jc  delex
  111.          mov  ax,0
  112.  
  113. delex:   mov  sp,bp
  114.          pop  bp
  115.          ret
  116.  
  117. _del     endp
  118.  
  119.  
  120.  
  121. ;----------------------------------------------------------------------------
  122. ;
  123. ;  l_seek(fh,offset,method)
  124. ;  int fh;             file handle
  125. ;  long offset;        offset in file to seek to (from start of file)
  126. ;   int  method;       - 0 - offset from beginning of file
  127. ;                       - 1 - offset from current position
  128. ;                       - 2 - from end of file
  129. ;
  130. ;  Seek to a specific position in file.
  131. ;
  132. ;------------------------------------------------------------------------------
  133.  
  134. PUBLIC  l_seek
  135.  
  136. l_seek PROC    NEAR
  137.         push    bp
  138.         mov     bp,sp
  139.  
  140. ;       Basically lseek(fh,offset,method)
  141.  
  142.         mov     ah,42h                 
  143.         mov     bx,[bp+4]              ;file handle
  144.         mov     cx,[bp+8]              ;offset (most significant)
  145.         mov     dx,[bp+6]              ;       (least significant)
  146.         mov     al,[bp+10]             ; get seek method
  147.  
  148.         int     21h
  149.  
  150. seekex: mov     sp,bp
  151.         pop     bp
  152.         ret
  153.  
  154. l_seek ENDP
  155.  
  156.  
  157. ;*****************************************************************************
  158. ;
  159. ;  r_ead(fh,bp,bl)
  160. ;  int fh;                     /* file handle */
  161. ;  char near *bp;               /* memory loc to read to */
  162. ;  unsigned int bl;            /* amount to read */
  163. ;
  164. ;  Read a buffer from the current location in file.
  165. ;
  166. ;*****************************************************************************
  167.  
  168.          PUBLIC  r_ead
  169.  
  170. r_ead    PROC NEAR
  171.          push bp
  172.          mov  bp,sp
  173.  
  174.          mov  ah,3fh              ;read file
  175.          mov  bx,[bp+4]           ;file handle
  176.          mov  cx,[bp+8]           ;bl (buffer length)
  177.          mov  dx,[bp+6]           ;bp (buffer pointer)
  178.          int  21h
  179.  
  180.          jnc  readex
  181.          mov  ax,-1               ; error reading file
  182.  
  183. readex:  mov  sp,bp
  184.          pop  bp
  185.          ret
  186.  
  187. r_ead    ENDP
  188.  
  189.  
  190. ;*****************************************************************************
  191. ;
  192. ;  w_rite(fh,bp,bl)
  193. ;  int fh;                     /* file handle */
  194. ;  char near *bp;              /* memory loc to read to */
  195. ;  unsigned int bl;            /* amount to read */
  196. ;
  197. ;  Write a buffer to the current location in file.
  198. ;
  199. ;*****************************************************************************
  200.  
  201.         PUBLIC  w_rite
  202.  w_rite   PROC NEAR
  203.           push    bp
  204.           mov     bp,sp
  205.  
  206.           push    ds                     ;save current data seg
  207.  
  208.           mov     ah,40h               ;write file
  209.           mov     bx,[bp+4]            ;file handle
  210.           mov     cx,[bp+8]            ;bl(buffer length)
  211.           mov     dx,[bp+6]            ;bp (buffer pointer)
  212.           int     21h
  213.  
  214.           jnc     writex               ;jmp if no error
  215.           mov     ax,-1                ;tell caller error happened
  216.  
  217. writex:   mov     sp,bp
  218.           pop     bp
  219.           ret
  220.  
  221. w_rite    ENDP
  222.  
  223.  
  224. ;*****************************************************************************
  225. ;
  226. ;  _setftime(fh,date,time)
  227. ;  int fh;                     /* file handle */
  228. ;  unsigned int date;          /* date to set on file */
  229. ;  unsigned int time;          /* time to set on file */
  230. ;
  231. ;  Set the creation/revision date/time on a file.
  232. ;
  233. ;*****************************************************************************
  234.  
  235.         PUBLIC  _setftime
  236.  
  237. _setftime PROC NEAR
  238.         push    bp
  239.         mov     bp,sp
  240.  
  241.         mov     ax,5701h               ;set file date/time function
  242.         mov     bx,[bp+4]              ;file handle
  243.         mov     cx,[bp+8]              ;file time
  244.         mov     dx,[bp+6]              ;file date
  245.         int     21h
  246.  
  247.         mov     sp,bp                  ;no error checking done
  248.         pop     bp
  249.         ret
  250.  
  251. _setftime ENDP
  252.  
  253.  
  254. ;-----------------------------------------------------------------------------
  255. ;
  256. ;  _getcdir(drive,buffer)
  257. ;  int drive;
  258. ;  char *buffer;
  259. ;
  260. ;  Get the current dir for given drive.
  261. ;
  262. ;-------------------------------------------------------------------------------
  263.  
  264.         PUBLIC  _getcdir
  265.  
  266. _getcdir PROC NEAR
  267.          push bp
  268.          mov  bp,sp
  269.  
  270.          push si
  271.  
  272.          mov  ah,47h                 ;get current dir
  273.          mov  dl,BYTE PTR [bp+4]     ;drive code to DL
  274.          mov  si,[bp+6]              ;buffer ptr to DS:SI
  275.          mov  BYTE PTR [si],0        ;make sure its terminated if error
  276.          int  21h
  277.          
  278.          pop  si
  279.          
  280.          mov  sp,bp                  ;no error checking done
  281.          pop  bp
  282.          ret
  283.          
  284. _getcdir ENDP
  285.  
  286. ;-----------------------------------------------------------------------------
  287. ;
  288. ;  _chdir(dir_name)
  289. ;  char *dir_name;           /* name of directory to make current */
  290. ;
  291. ;   returns   0 - successfull,  -1 - error
  292. ;-------------------------------------------------------------------------------
  293.  
  294.          PUBLIC  _chdir
  295.  
  296. _chdir PROC NEAR
  297.          push bp
  298.          mov  bp,sp
  299.  
  300.  
  301.          mov  ah,3bh                 ;get current dir
  302.          mov  dx,4[bp]               ; get offset to new dir name
  303.          int  21h
  304.  
  305.          mov  ax,0
  306.          jnc  endset
  307.          mov  ax,-1
  308.  
  309. endset:
  310.          mov  sp,bp                  ;no error checking done
  311.          pop  bp
  312.          ret
  313.          
  314. _chdir ENDP
  315.  
  316. ;-----------------------------------------------------------------------------
  317. ;   _MKDIR(dir_name)    - creates a new subdirectory
  318. ;
  319. ;   char *dir_name      - ptr to name of directory to create
  320. ;
  321. ;   returns   - 0 - successfull        3 - path not found
  322. ;                                      5 - access denied
  323. ;----------------------------------------------------------------------------
  324.  
  325. public   _mkdir
  326. _mkdir   proc near
  327.  
  328.     push bp
  329.     mov  bp,sp
  330.  
  331.     mov  dx,4[bp]       ; get ptr to dir to make
  332.     mov  ax,3900h
  333.     int  21h            ; call dos
  334.  
  335.     jc   mkdirex        ; keep error code in ax for return
  336.     mov  ax,00          ; no error
  337.  
  338.  
  339. mkdirex:
  340.     mov  sp,bp
  341.     pop  bp
  342.     ret
  343. _mkdir   endp
  344.  
  345.  
  346. ;-----------------------------------------------------------------------------
  347. ;   _RD(dir_name)  - removes a subdirectory
  348. ;
  349. ;   char *dir_name - ptr to dir name to remove
  350. ;
  351. ;   returns - 0 - successful      or  error code: 3 - path not found
  352. ;                                                 5 - dir not empty or 
  353. ;                                                     access denied
  354. ;------------------------------------------------------------------------------
  355.  
  356. public   _rd
  357. _rd proc near
  358.  
  359.          push bp
  360.          mov  bp,sp
  361.  
  362.          mov  dx,4[bp]       ; get dir name to remove
  363.          mov  ax,03a00h
  364.          int  21h
  365.  
  366.          jc   rdex
  367.          mov  ax,0
  368.  
  369. rdex:    mov  sp,bp
  370.          pop  bp
  371.          ret
  372. _rd endp
  373.  
  374.  
  375.  
  376.  
  377.  
  378. ;-----------------------------------------------------------------------------
  379. ;
  380. ;  _setattrib(fn,attrs)
  381. ;  char *fn;                   /* file name */
  382. ;  unsigned int attrs;         /* attributes to set */
  383. ;
  384. ;  Set the file attributes
  385. ;
  386. ;-----------------------------------------------------------------------------
  387.  
  388.         PUBLIC  _setattrib
  389.  
  390. _setattrib PROC NEAR
  391.         push    bp
  392.         mov     bp,sp
  393.  
  394.         mov     ax,4301h               ;CHMOD dos function
  395.         mov     cx,[bp+6]              ;file attributes
  396.         mov     dx,[bp+4]              ;file name
  397.         int     21h
  398.  
  399.         mov     sp,bp                  ;no error checking done
  400.         pop     bp
  401.         ret
  402.  
  403. _setattrib ENDP
  404.  
  405.  
  406. ;-----------------------------------------------------------------------------
  407. ;
  408. ;  unsigned int _getattrib(fn)
  409. ;  char *fn;                   /* file name */
  410. ;
  411. ;  get the file attributes
  412. ;  returns attributes in ax
  413. ;-----------------------------------------------------------------------------
  414.  
  415.         PUBLIC  _getattrib
  416.  
  417. _getattrib PROC NEAR
  418.         push  bp
  419.         mov   bp,sp
  420.  
  421.         mov   ax,4300h                 ;CHMOD dos function
  422.         mov   dx,[bp+4]                ;file name
  423.         int   21h
  424.  
  425.         mov   ax,cx                    ; mov attributes to cx for return to C
  426.         mov   sp,bp                    ;no error checking done
  427.         pop   bp
  428.         ret
  429.  
  430. _getattrib endp
  431.  
  432. include  endpseg.h
  433.  
  434.          end
  435.