|
@@ -6,14 +6,14 @@ unsigned char bom[] = { 0xEF, 0xBB, 0xBF };
|
|
|
|
|
|
int checkBOM(const char *filePath) {
|
|
|
FILE *inputFile = fopen(filePath, "r");
|
|
|
- if (inputFile == NULL) return ERROR;
|
|
|
+ if (inputFile == NULL) return ERROROPENINPUT;
|
|
|
|
|
|
unsigned char check[BOMSIZE];
|
|
|
if (BOMSIZE != fread(check, BOMSIZE, 1, inputFile)) {
|
|
|
if (feof(inputFile)) return NOBOM;
|
|
|
- if (ferror(inputFile)) return ERROR;
|
|
|
+ if (ferror(inputFile)) return ERRORINPUT;
|
|
|
}
|
|
|
- if (fclose(inputFile)) return ERROR;
|
|
|
+ if (fclose(inputFile)) return ERRORCLOSEINPUT;
|
|
|
|
|
|
if (!memcmp(&bom, check, BOMSIZE)) return HASBOM;
|
|
|
return NOBOM;
|
|
@@ -25,12 +25,12 @@ int removeBOM(const char *filePath) {
|
|
|
if (NOBOM == checkBOM(filePath)) return SUCCESS;
|
|
|
|
|
|
FILE *inputFile = fopen(filePath, "r");
|
|
|
- if (inputFile == NULL) return ERROR;
|
|
|
+ if (inputFile == NULL) return ERROROPENINPUT;
|
|
|
|
|
|
- if (fseek(inputFile, BOMSIZE, SEEK_SET)) return ERROR;
|
|
|
+ if (fseek(inputFile, BOMSIZE, SEEK_SET)) return ERRORSEEK;
|
|
|
|
|
|
FILE *tempFile = fopen(tempFileName, "w");
|
|
|
- if (tempFile == NULL) return ERROR;
|
|
|
+ if (tempFile == NULL) return ERROROPENTEMP;
|
|
|
|
|
|
char buffer[CHUNKSIZE];
|
|
|
do {
|
|
@@ -38,11 +38,11 @@ int removeBOM(const char *filePath) {
|
|
|
fwrite(buffer, 1, read, tempFile);
|
|
|
} while (!feof(inputFile));
|
|
|
|
|
|
- if (fclose(tempFile)) return ERROR;
|
|
|
- if (fclose(inputFile)) return ERROR;
|
|
|
+ if (fclose(tempFile)) return ERRORCLOSETEMP;
|
|
|
+ if (fclose(inputFile)) return ERRORCLOSEINPUT;
|
|
|
|
|
|
- if (remove(filePath)) return ERROR;
|
|
|
- if (rename(tempFileName, filePath)) return ERROR;
|
|
|
+ if (remove(filePath)) return ERRORREMOVE;
|
|
|
+ if (rename(tempFileName, filePath)) return ERRORRENAME;
|
|
|
|
|
|
return SUCCESS;
|
|
|
}
|
|
@@ -51,13 +51,13 @@ int addBOM(const char *filePath) {
|
|
|
if (HASBOM == checkBOM(filePath)) return SUCCESS;
|
|
|
|
|
|
FILE *inputFile = fopen(filePath, "r");
|
|
|
- if (inputFile == NULL) return ERROR;
|
|
|
+ if (inputFile == NULL) return ERROROPENINPUT;
|
|
|
|
|
|
FILE *tempFile = fopen(tempFileName, "w");
|
|
|
- if (tempFile== NULL) return ERROR;
|
|
|
+ if (tempFile== NULL) return ERROROPENTEMP;
|
|
|
|
|
|
int written = fwrite(bom, 1, BOMSIZE, tempFile);
|
|
|
- if (written != BOMSIZE) return ERROR;
|
|
|
+ if (written != BOMSIZE) return ERROROUTPUT;
|
|
|
|
|
|
char buffer[CHUNKSIZE];
|
|
|
do {
|
|
@@ -65,11 +65,11 @@ int addBOM(const char *filePath) {
|
|
|
fwrite(buffer, 1, read, tempFile);
|
|
|
} while (!feof(inputFile));
|
|
|
|
|
|
- if (fclose(tempFile)) return ERROR;
|
|
|
- if (fclose(inputFile)) return ERROR;
|
|
|
+ if (fclose(tempFile)) return ERRORCLOSETEMP;
|
|
|
+ if (fclose(inputFile)) return ERRORCLOSEINPUT;
|
|
|
|
|
|
- if (remove(filePath)) return ERROR;
|
|
|
- if (rename(tempFileName, filePath)) return ERROR;
|
|
|
+ if (remove(filePath)) return ERRORREMOVE;
|
|
|
+ if (rename(tempFileName, filePath)) return ERRORRENAME;
|
|
|
|
|
|
return SUCCESS;
|
|
|
}
|