1 #pragma once 2 3 Str *ReadFile(FILE *fp); 4 Str *ReadFile(const char *filename); 5 Str *ReadFile(Str *filename); 6 StrArr *ReadLines(const char *filename); 7 StrArr *ReadLines(Str *filename); 8 Str *ReadProcess(Str *prog, StrArr *args); 9 StrArr *ReadProcessLines(Str *prog, StrArr *args); 10 int WriteFile(FILE *fp, Str *data); 11 int WriteFile(Str *filename, Str *data); 12 int WriteFile(const char *filename, Str *data); 13 int WriteProcess(Str *prog, StrArr *args, Str *data); 14 int System(Str *prog, StrArr *args); 15 16 void Print(Str *str); 17 void Print(const char *str); 18 void Print(Int i); 19 void PrintErr(Str *str); 20 void PrintErr(const char *str); 21 void PrintErr(Int i); 22 void PrintLn(Str *str); 23 void PrintLn(const char *str); 24 void PrintLn(Int i); 25 void PrintErrLn(Str *str); 26 void PrintErrLn(const char *str); 27 void PrintErrLn(Int i); 28 29 enum ListFilesMode { 30 ListFilesAndDirs = 1, 31 ListFilesRelative = 2, 32 }; 33 34 Str *CurrentDir(); 35 bool ChDir(Str *path); 36 bool ChDir(const char *path); 37 StrArr *ListFiles(const char *path); 38 StrArr *ListFiles(Str *path); 39 StrArr *ListFiles(const char *path); 40 StrArr *ListFileTree(Str *path, int mode = 0); 41 StrArr *ListFileTree(const char *path, int mode = 0); 42 43 struct FileInfo : PtrFreeGC { 44 bool is_dir; 45 bool is_file; 46 bool is_link; 47 bool is_other; 48 double atime; // currently no nano-second resolution 49 double mtime; 50 double ctime; 51 #ifdef HAVE_OFF_T 52 Offset size; 53 #else 54 Int size; 55 #endif 56 }; 57 58 static const char *PathSeparator = "/"; 59 60 bool FileStat(FileInfo &info, const char *path, bool follow_links = false); 61 bool FileStat(FileInfo &info, Str *path, bool follow_links = false); 62 FileInfo *FileStat(const char *path, bool follow_links = false); 63 FileInfo *FileStat(Str *path, bool follow_links = false); 64 Str *DirName(Str *path); 65 Str *BaseName(Str *path); 66 Str *FileExtension(Str *path); 67 Str *AbsolutePath(Str *path); 68 Str *NormalizePath(Str *path); 69 Str *GetEnv(Str *name); 70 Str *GetEnv(const char *name); 71 72 Str *ProgramPath(); 73 74 bool MakeDir(Str *path, bool recursive = false); 75 bool MakeDir(const char *path, bool recursive = false); 76 bool RemoveDir(Str *path); 77 bool RemoveDir(const char *path); 78 bool RemoveFile(Str *path); 79 bool RemoveFile(const char *path); 80 bool Rename(Str *path, Str *path2); 81 bool Rename(const char *path, const char *path2); 82