| | 43 | /** |
| | 44 | Returns -1 if not present. |
| | 45 | */ |
| | 46 | int orFileSize( const char* path ) |
| | 47 | { |
| | 48 | struct stat buf; |
| | 49 | if( stat( path, &buf ) == -1 ) |
| | 50 | return -1; |
| | 51 | return buf.st_size; |
| | 52 | } |
| | 53 | |
| | 54 | |
| | 55 | /** |
| | 56 | Returns 1 if directory, 0 if file or -1 if error. |
| | 57 | */ |
| | 58 | int orIsDir( const char* path ) |
| | 59 | { |
| | 60 | struct stat buf; |
| | 61 | if( stat( path, &buf ) == -1 ) |
| | 62 | return -1; |
| | 63 | return S_ISDIR(buf.st_mode) ? 1 : 0; |
| | 64 | } |
| | 65 | |
| | 66 | |
| | 67 | /** |
| | 68 | Returns 0 if result set to file modification time or -1 if error. |
| | 69 | */ |
| | 70 | int orFileModified( const char* path, OValue* res ) |
| | 71 | { |
| | 72 | struct stat buf; |
| | 73 | if( stat( path, &buf ) == -1 ) |
| | 74 | return -1; |
| | 75 | |
| | 76 | orSetTF( res, OT_TIME ); |
| | 77 | res->time.sec = buf.st_mtime; |
| | 78 | res->time.usec = 0; |
| | 79 | return 0; |
| | 80 | } |
| | 81 | |
| | 82 | |
| 80 | | Returns -1 if not present. |
| 81 | | */ |
| 82 | | int orFileSize( const char* path ) |
| 83 | | { |
| 84 | | struct stat buf; |
| 85 | | if( stat( path, &buf ) == -1 ) |
| 86 | | return -1; |
| 87 | | return buf.st_size; |
| 88 | | } |
| 89 | | |
| 90 | | |
| 91 | | /** |
| 92 | | Returns 1 if directory, 0 if file or -1 if error. |
| 93 | | */ |
| 94 | | int orIsDir( const char* path ) |
| 95 | | { |
| 96 | | struct stat buf; |
| 97 | | if( stat( path, &buf ) == -1 ) |
| 98 | | return -1; |
| 99 | | return S_ISDIR(buf.st_mode) ? 1 : 0; |
| 100 | | } |
| 101 | | |
| 102 | | |
| 103 | | /** |
| 104 | | Returns 0 if result set to file modification time or -1 if error. |
| 105 | | */ |
| 106 | | int orFileModified( const char* path, OValue* res ) |
| 107 | | { |
| 108 | | struct stat buf; |
| 109 | | if( stat( path, &buf ) == -1 ) |
| 110 | | return -1; |
| 111 | | |
| 112 | | orSetTF( res, OT_TIME ); |
| 113 | | res->time.sec = buf.st_mtime; |
| 114 | | res->time.usec = 0; |
| 115 | | return 0; |
| | 122 | No error if directory exists. |
| | 123 | */ |
| | 124 | void orMakeDirNative( OValue* a1 ) |
| | 125 | { |
| | 126 | int err; |
| | 127 | OString* str = orSTRING(a1); |
| | 128 | orTermCStr(str); |
| | 129 | err = mkdir( str->charArray, 0755 ); |
| | 130 | if( err ) |
| | 131 | { |
| | 132 | if( (errno != EEXIST) || (orIsDir(str->charArray) != 1) ) |
| | 133 | { |
| | 134 | orErrorT( OR_ERROR_ACCESS, strerror/*_r*/(errno) ); |
| | 135 | } |
| | 136 | } |