- Remove the remaining __USE_W32API, deprecated for ages.
[reactos.git] / reactos / lib / fslib / vfatlib / check / file.c
index 9d6b4ff..097d23c 100644 (file)
@@ -5,30 +5,10 @@
 /* FAT32, VFAT, Atari format support, and various fixes additions May 1998
  * by Roman Hodek <Roman.Hodek@informatik.uni-erlangen.de> */
 
+#include "vfatlib.h"
 
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <ctype.h>
-//#include <unistd.h>
-
-#define _LINUX_STAT_H          /* hack to avoid inclusion of <linux/stat.h> */
-#define _LINUX_STRING_H_       /* hack to avoid inclusion of <linux/string.h>*/
-#define _LINUX_FS_H             /* hack to avoid inclusion of <linux/fs.h> */
-
-//#include <linux/version.h>
-//#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0)
-//# define __KERNEL__
-//# include <asm/types.h>
-//# undef __KERNEL__
-//#endif
-
-#include "dosfsck.h"
-#include "msdos_fs.h"
-
-#include "common.h"
-#include "file.h"
-
+#define NDEBUG
+#include <debug.h>
 
 FDSC *fp_root = NULL;
 
@@ -57,7 +37,7 @@ char *file_name(unsigned char *fixed)
            while (j++ < i) *p++ = ' ';
            put_char(&p,fixed[i]);
        }
-    if (strncmp(fixed+8,"   ",3)) {
+    if (strncmp((char*)fixed+8,"   ",3)) {
        *p++ = '.';
        for (i = j =  0; i < 3; i++)
            if (fixed[i+8] != ' ') {
@@ -69,7 +49,6 @@ char *file_name(unsigned char *fixed)
     return path;
 }
 
-
 int file_cvt(unsigned char *name,unsigned char *fixed)
 {
     unsigned char c;
@@ -80,13 +59,13 @@ int file_cvt(unsigned char *name,unsigned char *fixed)
     while (*name) {
        c = *name;
        if (c < ' ' || c > 0x7e || strchr("*?<>|\"/",c)) {
-           printf("Invalid character in name. Use \\ooo for special "
+           VfatPrint("Invalid character in name. Use \\ooo for special "
              "characters.\n");
            return 0;
        }
        if (c == '.') {
            if (ext) {
-               printf("Duplicate dots in name.\n");
+               VfatPrint("Duplicate dots in name.\n");
                return 0;
            }
            while (size--) *fixed++ = ' ';
@@ -99,13 +78,13 @@ int file_cvt(unsigned char *name,unsigned char *fixed)
            c = 0;
            for (cnt = 3; cnt; cnt--) {
                if (*name < '0' || *name > '7') {
-                   printf("Invalid octal character.\n");
+                   VfatPrint("Invalid octal character.\n");
                    return 0;
                }
                c = c*8+*name++-'0';
            }
            if (cnt < 4) {
-               printf("Expected three octal digits.\n");
+               VfatPrint("Expected three octal digits.\n");
                return 0;
            }
            name += 3;
@@ -138,14 +117,14 @@ void file_add(char *path,FD_TYPE type)
     path++;
     while (1) {
        if ((here = strchr(path,'/'))) *here = 0;
-       if (!file_cvt(path,name)) exit(2);
+    if (!file_cvt((unsigned char*)path,(unsigned char *)name)) {return; /*exit(2);*/}
        for (walk = *current; walk; walk = walk->next)
            if (!here && (!strncmp(name,walk->name,MSDOS_NAME) || (type ==
              fdt_undelete && !strncmp(name+1,walk->name+1,MSDOS_NAME-1))))
                die("Ambiguous name: \"%s\"",path);
            else if (here && !strncmp(name,walk->name,MSDOS_NAME)) break;
        if (!walk) {
-           walk = alloc(sizeof(FDSC));
+           walk = vfalloc(sizeof(FDSC));
            strncpy(walk->name,name,MSDOS_NAME);
            walk->type = here ? fdt_none : type;
            walk->first = NULL;
@@ -201,26 +180,26 @@ FD_TYPE file_type(FDSC **curr,char *fixed)
 }
 
 
-void file_modify(FDSC **curr,char *fixed)
+void file_modify(FDSC **curr,unsigned char *fixed)
 {
     FDSC **this,*next;
 
-    if (!(this = file_find(curr,fixed)))
+    if (!(this = file_find(curr,(char *)fixed)))
        die("Internal error: file_find failed");
     switch ((*this)->type) {
        case fdt_drop:
-           printf("Dropping %s\n",file_name(fixed));
-           *(unsigned char *) fixed = DELETED_FLAG;
+           VfatPrint("Dropping %s\n",file_name(fixed));
+           *fixed = DELETED_FLAG;
            break;
        case fdt_undelete:
            *fixed = *(*this)->name;
-           printf("Undeleting %s\n",file_name(fixed));
+           VfatPrint("Undeleting %s\n",file_name(fixed));
            break;
        default:
            die("Internal error: file_modify");
     }
     next = (*this)->next;
-    free(*this);
+    vffree(*this);
     *this = next;
 }
 
@@ -233,9 +212,9 @@ static void report_unused(FDSC *this)
        next = this->next;
        if (this->first) report_unused(this->first);
        else if (this->type != fdt_none)
-               printf("Warning: did not %s file %s\n",this->type == fdt_drop ?
-                 "drop" : "undelete",file_name(this->name));
-       free(this);
+               VfatPrint("Warning: did not %s file %s\n",this->type == fdt_drop ?
+                 "drop" : "undelete",file_name((unsigned char*)this->name));
+       vffree(this);
        this = next;
     }
 }