home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 2 BBS / 02-BBS.zip / XGRP_000.SZH / MUNLINK.C < prev    next >
C/C++ Source or Header  |  1991-08-21  |  2KB  |  95 lines

  1. #define INCL_DOS
  2.  
  3. #include <stddef.h>
  4. #include <stdarg.h>
  5. #include <stdio.h>
  6. #include <string.h>
  7. #include <malloc.h>
  8. #include <io.h>
  9. #include <process.h>
  10. #include <errno.h>
  11. #ifdef TSC
  12.   #define _cdecl cdecl
  13.   #include <os2kernl.h>
  14. #else
  15.   #include <os2.h>
  16. #endif
  17. #include "nofast.h"
  18.  
  19.  
  20. extern void _cdecl    logf (char *szFormat, ...);
  21. extern void _fastcall my_free(void *ptr);
  22.  
  23.  
  24. int _fastcall my_unlink (char *fname) {
  25.  
  26.     int counter = 0;
  27.  
  28.  
  29.     while(unlink(fname) && (counter++ < 121)) {
  30.         if(errno == ENOENT) return 0;
  31.         if(errno == EACCES) {
  32.             if(counter == 2)
  33.               printf("\nTrouble unlinking %s...retry #",fname);
  34.             if(counter > 1) {
  35.                 printf("%-5u\b\b\b\b\b",counter);
  36.                 DosSleep(1000L);
  37.             }
  38.         }
  39.         else {
  40.             logf("Couldn't unlink %s -- errno = %u",fname,errno);
  41.             return -1;
  42.         }
  43.     }
  44.  
  45.     if(counter) printf("\n");
  46.  
  47.     if(counter > 120) {
  48.         logf("Couldn't unlink \"%s\"; please exterminate",fname);
  49.         return -1;
  50.     }
  51.  
  52.     return 0;
  53. }
  54.  
  55.  
  56.  
  57. int _fastcall my_rename (char *oname,char *nname) {
  58.  
  59.     int counter = 0;
  60.  
  61.  
  62.     while(rename(oname,nname) && (counter++ < 121)) {
  63.         if(errno == ENOENT) return -1;
  64.         if(errno == EACCES) {
  65.             if(counter == 2)
  66.               printf("\nTrouble renaming %s to %s...retry #",oname,nname);
  67.             if(counter > 1) {
  68.                 printf("%-5u\b\b\b\b\b",counter);
  69.                 DosSleep(1000L);
  70.             }
  71.         }
  72.         else {
  73.             logf("Couldn't rename %s to %s -- errno = %u",oname,nname,errno);
  74.             return -1;
  75.         }
  76.     }
  77.  
  78.     if(counter) printf("\n");
  79.  
  80.     if(counter > 120) {
  81.         logf("Couldn't rename \"%s\" to \"%s\"",oname,nname);
  82.         return -1;
  83.     }
  84.  
  85.     return 0;
  86. }
  87.  
  88.  
  89.  
  90.  
  91. void _fastcall my_free (void *ptr) {
  92.  
  93.     if(ptr != NULL) free(ptr);
  94. }
  95.