ObjFW  Diff

Differences From Artifact [79751d7dbc]:

  • File src/OFFile.m — part of check-in [8d2a5052fd] at 2014-01-25 17:39:13 on branch trunk — Generalize stream / socket related exceptions

    This is in preparation for adding UDP sockets, as UDP sockets and TCP
    sockets have no common superclass, as one is stream-oriented while the
    other is packet-oriented.

    Read and write exceptions are for any object now, as they are useful for
    a lot more than just for streams, while the others (bind, listen, etc.)
    are for any socket now (the type is id in this case, though, as there is
    no common superclass). (user: js, size: 20463) [annotate] [blame] [check-ins using]

To Artifact [8e458eea83]:


324
325
326
327
328
329
330

331

332
333
334
335
336
337
338
339
340
341


342
343
344
345
346
347
348

	objc_autoreleasePoolPop(pool);
}

+ (OFArray*)contentsOfDirectoryAtPath: (OFString*)path
{
	OFMutableArray *files;

	of_string_encoding_t encoding;


	if (path == nil)
		@throw [OFInvalidArgumentException exception];

	files = [OFMutableArray array];
	encoding = [OFString nativeOSEncoding];

#ifndef _WIN32
	DIR *dir;
	struct dirent *dirent;



	if ((dir = opendir([path cStringWithEncoding: encoding])) == NULL)
		@throw [OFOpenFileFailedException exceptionWithPath: path
							       mode: @"r"];

	@try {
		while ((dirent = readdir(dir)) != NULL) {







>

>





<




>
>







324
325
326
327
328
329
330
331
332
333
334
335
336
337
338

339
340
341
342
343
344
345
346
347
348
349
350
351

	objc_autoreleasePoolPop(pool);
}

+ (OFArray*)contentsOfDirectoryAtPath: (OFString*)path
{
	OFMutableArray *files;
#ifndef _WIN32
	of_string_encoding_t encoding;
#endif

	if (path == nil)
		@throw [OFInvalidArgumentException exception];

	files = [OFMutableArray array];


#ifndef _WIN32
	DIR *dir;
	struct dirent *dirent;

	encoding = [OFString nativeOSEncoding];

	if ((dir = opendir([path cStringWithEncoding: encoding])) == NULL)
		@throw [OFOpenFileFailedException exceptionWithPath: path
							       mode: @"r"];

	@try {
		while ((dirent = readdir(dir)) != NULL) {
642
643
644
645
646
647
648

649

650
651
652
653
654
655
656
657
658
659
660
661
662

663
664
665
666
667
668
669
670
671
672
}

+ (void)moveItemAtPath: (OFString*)source
		toPath: (OFString*)destination
{
	void *pool;
	of_stat_t s;

	of_string_encoding_t encoding;


	if (source == nil || destination == nil)
		@throw [OFInvalidArgumentException exception];

	pool = objc_autoreleasePoolPush();

	if (of_lstat(destination, &s) == 0) {
		errno = EEXIST;
		@throw [OFCopyItemFailedException
		    exceptionWithSourcePath: source
			    destinationPath: destination];
	}


	encoding = [OFString nativeOSEncoding];

#ifndef _WIN32
	if (rename([source cStringWithEncoding: encoding],
	    [destination cStringWithEncoding: encoding])) {
#else
	if (_wrename([source UTF16String], [destination UTF16String])) {
#endif
		if (errno != EXDEV)
			@throw [OFMoveItemFailedException







>

>













>


<







645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670

671
672
673
674
675
676
677
}

+ (void)moveItemAtPath: (OFString*)source
		toPath: (OFString*)destination
{
	void *pool;
	of_stat_t s;
#ifndef _WIN32
	of_string_encoding_t encoding;
#endif

	if (source == nil || destination == nil)
		@throw [OFInvalidArgumentException exception];

	pool = objc_autoreleasePoolPush();

	if (of_lstat(destination, &s) == 0) {
		errno = EEXIST;
		@throw [OFCopyItemFailedException
		    exceptionWithSourcePath: source
			    destinationPath: destination];
	}

#ifndef _WIN32
	encoding = [OFString nativeOSEncoding];


	if (rename([source cStringWithEncoding: encoding],
	    [destination cStringWithEncoding: encoding])) {
#else
	if (_wrename([source UTF16String], [destination UTF16String])) {
#endif
		if (errno != EXDEV)
			@throw [OFMoveItemFailedException