Skip to content

Commit 0ad8d9a

Browse files
authored
Update functions.c
1 parent 92a871f commit 0ad8d9a

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

c/functions.c

+30
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ struct TidyResult{
1919
TidyBoolean error;
2020
};
2121
typedef struct TidyResult TidyResult;
22+
2223
TidyBoolean tidyFML_exists(const char tidyPath[]){
2324
#ifdef _WIN32
2425
DWORD tidyAttributes = GetFileAttributes(tidyPath);
@@ -202,3 +203,32 @@ TidyBoolean tidyFML_clear(const char tidyPath[]){
202203
}
203204
return FALSE;
204205
}
206+
207+
long tidyFML_fileSize(const char[] tidyPath){
208+
#ifdef WIN32
209+
HANDLE hFile = CreateFile(
210+
tidyPath,
211+
GENERIC_READ,
212+
FILE_SHARE_READ,
213+
NULL,
214+
OPEN_EXISTING,
215+
FILE_ATTRIBUTE_NORMAL,
216+
NULL
217+
);
218+
if(hFile == INVALID_HANDLE_FILE){
219+
return -1;
220+
}
221+
DWORD tidySize = GetFileSize(hFile, NULL);
222+
CloseHandle(hFile);
223+
if(tidySize == INVALID_FILE_SIZE){
224+
return -1;
225+
}
226+
else{
227+
return (long)tidySize;
228+
}
229+
#else
230+
struct stat st;
231+
stat(tidyPath, &st);
232+
return (long)st.st_size;
233+
#endif
234+
}

0 commit comments

Comments
 (0)