ObjFW
OFFile.h
1 /*
2  * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015
3  * Jonathan Schleifer <js@webkeks.org>
4  *
5  * All rights reserved.
6  *
7  * This file is part of ObjFW. It may be distributed under the terms of the
8  * Q Public License 1.0, which can be found in the file LICENSE.QPL included in
9  * the packaging of this file.
10  *
11  * Alternatively, it may be distributed under the terms of the GNU General
12  * Public License, either version 2 or 3, which can be found in the file
13  * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
14  * file.
15  */
16 
17 #ifndef __STDC_LIMIT_MACROS
18 # define __STDC_LIMIT_MACROS
19 #endif
20 #ifndef __STDC_CONSTANT_MACROS
21 # define __STDC_CONSTANT_MACROS
22 #endif
23 
24 #include <sys/types.h>
25 #include <sys/stat.h>
26 
27 #import "OFSeekableStream.h"
28 
29 OF_ASSUME_NONNULL_BEGIN
30 
31 @class OFArray OF_GENERIC(ObjectType);
32 @class OFDate;
33 
34 #if defined(_WIN32)
35 typedef struct __stat64 of_stat_t;
36 #elif defined(OF_HAVE_OFF64_T)
37 typedef struct stat64 of_stat_t;
38 #else
39 typedef struct stat of_stat_t;
40 #endif
41 
48 {
49  int _fd;
50  bool _atEndOfStream;
51 }
52 
75 + (instancetype)fileWithPath: (OFString*)path
76  mode: (OFString*)mode;
77 
85 + (instancetype)fileWithFileDescriptor: (int)fd;
86 
92 + (OFString*)currentDirectoryPath;
93 
100 + (bool)fileExistsAtPath: (OFString*)path;
101 
108 + (bool)directoryExistsAtPath: (OFString*)path;
109 
110 #ifdef OF_HAVE_SYMLINK
111 
117 + (bool)symbolicLinkExistsAtPath: (OFString*)path;
118 #endif
119 
125 + (void)createDirectoryAtPath: (OFString*)path;
126 
133 + (void)createDirectoryAtPath: (OFString*)path
134  createParents: (bool)createParents;
135 
144 + (OFArray OF_GENERIC(OFString*)*)contentsOfDirectoryAtPath: (OFString*)path;
145 
151 + (void)changeCurrentDirectoryPath: (OFString*)path;
152 
158 + (of_offset_t)sizeOfFileAtPath: (OFString*)path;
159 
165 + (OFDate*)accessTimeOfItemAtPath: (OFString*)path;
166 
172 + (OFDate*)modificationTimeOfItemAtPath: (OFString*)path;
173 
179 + (OFDate*)statusChangeTimeOfItemAtPath: (OFString*)path;
180 
181 #ifdef OF_HAVE_CHMOD
182 
190 + (void)changePermissionsOfItemAtPath: (OFString*)path
191  permissions: (mode_t)permissions;
192 #endif
193 
194 #ifdef OF_HAVE_CHOWN
195 
204 + (void)changeOwnerOfItemAtPath: (OFString*)path
205  owner: (OFString*)owner
206  group: (OFString*)group;
207 #endif
208 
222 + (void)copyItemAtPath: (OFString*)source
223  toPath: (OFString*)destination;
224 
238 + (void)moveItemAtPath: (OFString*)source
239  toPath: (OFString*)destination;
240 
248 + (void)removeItemAtPath: (OFString*)path;
249 
250 #ifdef OF_HAVE_LINK
251 
262 + (void)linkItemAtPath: (OFString*)source
263  toPath: (OFString*)destination;
264 #endif
265 
266 #ifdef OF_HAVE_SYMLINK
267 
280 + (void)createSymbolicLinkAtPath: (OFString*)destination
281  withDestinationPath: (OFString*)source;
282 
289 + (OFString*)destinationOfSymbolicLinkAtPath: (OFString*)path;
290 #endif
291 
314 - initWithPath: (OFString*)path
315  mode: (OFString*)mode;
316 
323 - initWithFileDescriptor: (int)fd;
324 @end
325 
326 #ifdef __cplusplus
327 extern "C" {
328 #endif
329 extern int of_stat(OFString *path, of_stat_t *buffer);
330 extern int of_lstat(OFString *path, of_stat_t *buffer);
331 #ifdef __cplusplus
332 }
333 #endif
334 
335 OF_ASSUME_NONNULL_END
An abstract class for storing objects in an array.
Definition: OFArray.h:95
A class for storing, accessing and comparing dates.
Definition: OFDate.h:30
A class for handling strings.
Definition: OFString.h:91
A class which provides functions to read, write and manipulate files.
Definition: OFFile.h:47
A stream that supports seeking.
Definition: OFSeekableStream.h:51