ObjFW  Diff

Differences From Artifact [fa2705caf0]:

To Artifact [cf4978d29a]:


35
36
37
38
39
40
41
42

43
44
45
46
47
48
49
35
36
37
38
39
40
41

42
43
44
45
46
47
48
49







-
+







#ifdef HAVE_SYS_STAT_H
# include <sys/stat.h>
#endif
#include <sys/time.h>
#if defined(OF_LINUX) || defined(OF_MACOS)
# include <sys/xattr.h>
#endif
#ifdef OF_NETBSD
#if defined(OF_FREEBSD) || defined(OF_NETBSD)
# include <sys/extattr.h>
#endif
#ifdef OF_HAIKU
# include <ctype.h>
# include <kernel/fs_attr.h>
#endif
#ifdef OF_WINDOWS
153
154
155
156
157
158
159





160
161
162
163
164
165
166
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171







+
+
+
+
+








#ifdef OF_WINDOWS
static int (*_wutime64FuncPtr)(const wchar_t *, struct __utimbuf64 *);
static WINAPI BOOLEAN (*createSymbolicLinkWFuncPtr)(LPCWSTR, LPCWSTR, DWORD);
static WINAPI BOOLEAN (*createHardLinkWFuncPtr)(LPCWSTR, LPCWSTR,
    LPSECURITY_ATTRIBUTES);
#endif

#if defined(OF_FREEBSD) || defined(OF_NETBSD)
static const char *namespaces[] = EXTATTR_NAMESPACE_NAMES;
static int numNamespaces = sizeof(namespaces) / sizeof(*namespaces);
#endif

#ifdef OF_WINDOWS
static OFTimeInterval
filetimeToTimeInterval(const FILETIME *filetime)
{
	return (double)((int64_t)filetime->dwHighDateTime << 32 |
	    filetime->dwLowDateTime) / 10000000.0 - 11644473600.0;
381
382
383
384
385
386
387
388

389
390
391
392
393

394
395
396
397
398

399

400
401
402




403
404
405





406
407
408
409
410
411
412
386
387
388
389
390
391
392

393
394
395
396
397
398
399
400
401
402
403
404
405
406
407



408
409
410
411



412
413
414
415
416
417
418
419
420
421
422
423







-
+





+





+

+
-
-
-
+
+
+
+
-
-
-
+
+
+
+
+








	return 0;
#else
	return statWrapper(path, buffer);
#endif
}

#ifdef OF_NETBSD
#if defined(OF_FREEBSD) || defined(OF_NETBSD)
static void
parseAttributeName(OFString **name, int *namespace)
{
	size_t pos = [*name rangeOfString: @"."].location;
	OFString *namespaceName;
	const char *cNamespace;

	if (pos == OFNotFound)
		@throw [OFInvalidArgumentException exception];

	namespaceName = [*name substringToIndex: pos];
	cNamespace = [namespaceName cStringWithEncoding: [OFLocale encoding]];

	*name = [*name substringFromIndex: pos + 1];
	if (extattr_string_to_namespace(
	    [namespaceName cStringWithEncoding: [OFLocale encoding]],
	    namespace) == -1)

	for (int i = 0; i < numNamespaces; i++) {
		if (strcmp(namespaces[i], cNamespace) == 0) {
			*namespace = i;
		@throw [OFInvalidArgumentException exception];

	*name = [*name substringFromIndex: pos + 1];
			return;
		}
	}

	@throw [OFInvalidArgumentException exception];
}
#endif

static void
setTypeAttribute(OFMutableFileAttributes attributes, Stat *s)
{
	if (S_ISREG(s->st_mode))
654
655
656
657
658
659
660
661

662
663
664

665
666
667
668

669
670
671
672
673
674

675
676
677
678
679
680
681
682



683
684
685


686
687
688
689
690
691
692
665
666
667
668
669
670
671

672
673
674

675
676
677
678

679

680
681
682
683

684








685
686
687
688


689
690
691
692
693
694
695
696
697







-
+


-
+



-
+
-




-
+
-
-
-
-
-
-
-
-
+
+
+

-
-
+
+








			name += length + 1;
			size -= length + 1;
		}
	} @finally {
		OFFreeMemory(list);
	}
# elif defined(OF_NETBSD)
# elif defined(OF_FREEBSD) || defined(OF_NETBSD)
	names = [OFMutableArray array];

	for (size_t i = 0; extattr_namespaces[i] != 0; i++) {
	for (int i = 0; i < numNamespaces; i++) {
		ssize_t size;
		char *list;

		if ((size = extattr_list_link(cPath, extattr_namespaces[i],
		if ((size = extattr_list_link(cPath, i, NULL, 0)) < 0)
		    NULL, 0)) < 0)
			continue;

		list = OFAllocMemory(1, size);
		@try {
			OFString *namespace;
			OFString *namespace = [OFString
			char *cNamespace, *iter;

			if (extattr_namespace_to_string(
			    extattr_namespaces[i], &cNamespace) == -1)
				continue;

			namespace = [OFString stringWithCString: cNamespace
						       encoding: encoding];
			    stringWithCString: namespaces[i]
				     encoding: encoding];
			char *iter;

			if ((size = extattr_list_link(cPath,
			    extattr_namespaces[i], list, size)) < 0)
			if ((size = extattr_list_link(cPath, i,
			    list, size)) < 0)
				continue;

			iter = list;

			while (size > 0) {
				ssize_t length = *(unsigned char *)iter;
				OFString *name;
1740
1741
1742
1743
1744
1745
1746
1747

1748
1749
1750
1751
1752
1753
1754
1745
1746
1747
1748
1749
1750
1751

1752
1753
1754
1755
1756
1757
1758
1759







-
+







		value = NULL;
	} @finally {
		OFFreeMemory(value);
	}

	if (type != NULL)
		*type = nil;
# elif defined(OF_NETBSD)
# elif defined(OF_FREEBSD) || defined(OF_NETBSD)
	int namespace;
	const char *cName;
	ssize_t size;

	parseAttributeName(&name, &namespace);
	cName = [name cStringWithEncoding: encoding];

1855
1856
1857
1858
1859
1860
1861
1862

1863
1864
1865
1866
1867
1868
1869
1860
1861
1862
1863
1864
1865
1866

1867
1868
1869
1870
1871
1872
1873
1874







-
+







		/* TODO: Add an attribute (prefix?) for extended attributes? */
		@throw [OFSetItemAttributesFailedException
		    exceptionWithIRI: IRI
			  attributes: [OFDictionary dictionary]
		     failedAttribute: @""
			       errNo: errNo];
	}
# elif defined(OF_NETBSD)
# elif defined(OF_FREEBSD) || defined(OF_NETBSD)
	int namespace;
	const char *cName;

	if (size > SSIZE_MAX)
		@throw [OFOutOfRangeException exception];

	if (type != nil)
1953
1954
1955
1956
1957
1958
1959
1960

1961
1962
1963
1964
1965
1966
1967
1958
1959
1960
1961
1962
1963
1964

1965
1966
1967
1968
1969
1970
1971
1972







-
+







		/* TODO: Add an attribute (prefix?) for extended attributes? */
		@throw [OFSetItemAttributesFailedException
		    exceptionWithIRI: IRI
			  attributes: [OFDictionary dictionary]
		     failedAttribute: @""
			       errNo: errNo];
	}
# elif defined(OF_NETBSD)
# elif defined(OF_FREEBSD) || defined(OF_NETBSD)
	int namespace;
	const char *cName;

	parseAttributeName(&name, &namespace);
	cName = [name cStringWithEncoding: encoding];

	if (extattr_delete_link(cPath, namespace, cName) != 0) {