Index: src/OFExceptions.h ================================================================== --- src/OFExceptions.h +++ src/OFExceptions.h @@ -7,12 +7,13 @@ * This file is part of ObjFW. It may be distributed under the terms of the * Q Public License 1.0, which can be found in the file LICENSE included in * the packaging of this file. */ +#include + #import "OFObject.h" -#import "OFFile.h" @class OFString; /** * An exception indicating an object could not be allocated. @@ -376,10 +377,11 @@ * \return The new mode for the file */ - (mode_t)mode; @end +#ifndef _WIN32 /** * An OFException indicating that changing the owner of the file failed. */ @interface OFChangeFileOwnerFailedException: OFException { @@ -433,10 +435,11 @@ /** * \return The new group for the file */ - (gid_t)group; @end +#endif /** * An OFException indicating that renaming a file failed. */ @interface OFRenameFileFailedException: OFException @@ -520,10 +523,11 @@ * \return The path of the file */ - (OFString*)path; @end +#ifndef _WIN32 /** * An OFException indicating that creating a link failed. */ @interface OFLinkFailedException: OFException { @@ -615,10 +619,11 @@ /** * \return A string of the destination for the symlink */ - (OFString*)destination; @end +#endif /** * An OFException indicating that setting an option failed. */ @interface OFSetOptionFailedException: OFException {} Index: src/OFExceptions.m ================================================================== --- src/OFExceptions.m +++ src/OFExceptions.m @@ -549,10 +549,11 @@ { return mode; } @end +#ifndef _WIN32 @implementation OFChangeFileOwnerFailedException + newWithClass: (Class)class__ path: (OFString*)path_ owner: (uid_t)owner_ group: (gid_t)group_ @@ -621,10 +622,11 @@ - (gid_t)group { return group; } @end +#endif @implementation OFRenameFileFailedException + newWithClass: (Class)class__ from: (OFString*)from_ to: (OFString*)to_ @@ -742,10 +744,11 @@ { return path; } @end +#ifndef _WIN32 @implementation OFLinkFailedException + newWithClass: (Class)class__ source: (OFString*)src_ destination: (OFString*)dest_ { @@ -871,10 +874,11 @@ - (OFString*)destination { return dest; } @end +#endif @implementation OFSetOptionFailedException - (OFString*)string { if (string != nil) Index: src/OFFile.h ================================================================== --- src/OFFile.h +++ src/OFFile.h @@ -9,16 +9,11 @@ * the packaging of this file. */ #include -#ifndef _WIN32 #include -#else -typedef int uid_t; -typedef int gid_t; -#endif #import "OFStream.h" @class OFString; @@ -47,19 +42,20 @@ + fileWithFilePointer: (FILE*)fp; /** * Changes the mode of a file. * - * Not available on Windows. + * Only changes read-only flag on Windows. * * \param path The path to the file of which the mode should be changed as a * string * \param mode The new mode for the file */ + (void)changeModeOfFile: (OFString*)path toMode: (mode_t)mode; +#ifndef _WIN32 /** * Changes the owner of a file. * * Not available on Windows. * @@ -69,10 +65,11 @@ * \param group The new group for the file */ + (void)changeOwnerOfFile: (OFString*)path toOwner: (uid_t)owner group: (gid_t)group; +#endif /** * Renames a file. * * \param from The file to rename @@ -86,10 +83,11 @@ * * \param path The path to the file of which should be deleted as a string */ + (void)delete: (OFString*)path; +#ifndef _WIN32 /** * Hardlinks a file. * * Not available on Windows. * @@ -107,10 +105,11 @@ * \param src The path to the file of which should be symlinked as a string * \param dest The path to where the file should be symlinked as a string */ + (void)symlink: (OFString*)src to: (OFString*)dest; +#endif /** * Initializes an already allocated OFFile. * * \param path The path to the file to open as a string Index: src/OFFile.m ================================================================== --- src/OFFile.m +++ src/OFFile.m @@ -13,21 +13,19 @@ #include #include #include -#ifndef _WIN32 #include #include -#endif #import "OFFile.h" #import "OFString.h" #import "OFExceptions.h" #ifdef _WIN32 -#import +# import #endif OFFile *of_stdin = nil; OFFile *of_stdout = nil; OFFile *of_stderr = nil; @@ -81,25 +79,22 @@ path: path mode: mode]; #endif } +#ifndef _WIN32 + (void)changeOwnerOfFile: (OFString*)path toOwner: (uid_t)owner group: (gid_t)group { -#ifndef _WIN32 if (chown([path cString], owner, group)) @throw [OFChangeFileOwnerFailedException newWithClass: self path: path owner: owner group: group]; -#else - @throw [OFNotImplementedException newWithClass: self - selector: _cmd]; -#endif } +#endif + (void)rename: (OFString*)from to: (OFString*)to { #ifndef _WIN32 @@ -121,37 +116,29 @@ #endif @throw [OFDeleteFileFailedException newWithClass: self path: path]; } +#ifndef _WIN32 + (void)link: (OFString*)src to: (OFString*)dest { -#ifndef _WIN32 if (link([src cString], [dest cString]) != 0) @throw [OFLinkFailedException newWithClass: self source: src destination: dest]; -#else - @throw [OFNotImplementedException newWithClass: self - selector: _cmd]; -#endif } + (void)symlink: (OFString*)src to: (OFString*)dest { -#ifndef _WIN32 if (symlink([src cString], [dest cString]) != 0) @throw [OFSymlinkFailedException newWithClass: self source: src destination: dest]; -#else - @throw [OFNotImplementedException newWithClass: self - selector: _cmd]; -#endif } +#endif - init { @throw [OFNotImplementedException newWithClass: isa selector: _cmd];