ObjFW  Check-in [1fedd3e87a]

Overview
Comment:OFFileURLHandler: Weakly link _wutime64

This also adds a fallback to _wutime if _wutime64 is unavailable.

Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | set-mtime
Files: files | file ages | folders
SHA3-256: 1fedd3e87a8a99e6517fad75c640e0999911b097c4513451544550afbbf0ce3f
User & Date: js on 2020-06-01 18:24:26
Other Links: branch diff | manifest | tags
Context
2020-06-01
18:46
OFFileURLHandler: Support setting mtime on Win98 check-in: cf233b2d5b user: js tags: set-mtime
18:24
OFFileURLHandler: Weakly link _wutime64 check-in: 1fedd3e87a user: js tags: set-mtime
17:55
OFFileURLHandler: Support setting mtime on Windows check-in: 05da423cc9 user: js tags: set-mtime
Changes

Modified src/OFFileURLHandler.m from [605a683718] to [8f66089176].

110
111
112
113
114
115
116

117
118
119
120
121
122
123
static OFMutex *passwdMutex;
#endif
#if !defined(HAVE_READDIR_R) && defined(OF_HAVE_THREADS) && !defined(OF_WINDOWS)
static OFMutex *readdirMutex;
#endif

#ifdef OF_WINDOWS

static WINAPI BOOLEAN (*func_CreateSymbolicLinkW)(LPCWSTR, LPCWSTR, DWORD);
static WINAPI BOOLEAN (*func_CreateHardLinkW)(LPCWSTR, LPCWSTR,
    LPSECURITY_ATTRIBUTES);
#endif

#ifdef OF_WINDOWS
static of_time_interval_t







>







110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
static OFMutex *passwdMutex;
#endif
#if !defined(HAVE_READDIR_R) && defined(OF_HAVE_THREADS) && !defined(OF_WINDOWS)
static OFMutex *readdirMutex;
#endif

#ifdef OF_WINDOWS
static int (*func__wutime64)(const wchar_t *, struct __utimbuf64 *);
static WINAPI BOOLEAN (*func_CreateSymbolicLinkW)(LPCWSTR, LPCWSTR, DWORD);
static WINAPI BOOLEAN (*func_CreateHardLinkW)(LPCWSTR, LPCWSTR,
    LPSECURITY_ATTRIBUTES);
#endif

#ifdef OF_WINDOWS
static of_time_interval_t
514
515
516
517
518
519
520




521
522
523
524
525
526
527
	passwdMutex = [[OFMutex alloc] init];
#endif
#if !defined(HAVE_READDIR_R) && !defined(OF_WINDOWS) && defined(OF_HAVE_THREADS)
	readdirMutex = [[OFMutex alloc] init];
#endif

#ifdef OF_WINDOWS




	if ((module = LoadLibrary("kernel32.dll")) != NULL) {
		func_CreateSymbolicLinkW =
		    (WINAPI BOOLEAN (*)(LPCWSTR, LPCWSTR, DWORD))
		    GetProcAddress(module, "CreateSymbolicLinkW");
		func_CreateHardLinkW =
		    (WINAPI BOOLEAN (*)(LPCWSTR, LPCWSTR,
		    LPSECURITY_ATTRIBUTES))







>
>
>
>







515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
	passwdMutex = [[OFMutex alloc] init];
#endif
#if !defined(HAVE_READDIR_R) && !defined(OF_WINDOWS) && defined(OF_HAVE_THREADS)
	readdirMutex = [[OFMutex alloc] init];
#endif

#ifdef OF_WINDOWS
	if ((module = LoadLibrary("msvcrt.dll")) != NULL)
		func__wutime64 = (int (*)(const wchar_t *,
		    struct __utimbuf64 *))GetProcAddress(module, "_wutime64");

	if ((module = LoadLibrary("kernel32.dll")) != NULL) {
		func_CreateSymbolicLinkW =
		    (WINAPI BOOLEAN (*)(LPCWSTR, LPCWSTR, DWORD))
		    GetProcAddress(module, "CreateSymbolicLinkW");
		func_CreateHardLinkW =
		    (WINAPI BOOLEAN (*)(LPCWSTR, LPCWSTR,
		    LPSECURITY_ATTRIBUTES))
606
607
608
609
610
611
612

613
614
615
616
617
618



619
620
621











622





623


624
625
626
627
628
629
630
- (void)of_setModificationDate: (OFDate *)date
		   ofItemAtURL: (OFURL *)URL
		    attributes: (of_file_attributes_t)attributes
{
	of_time_interval_t timeInterval = date.timeIntervalSince1970;
	OFString *path = URL.fileSystemRepresentation;
#ifdef OF_WINDOWS

	struct __utimbuf64 times = {
		(__time64_t)timeInterval,
		(__time64_t)timeInterval
	};

	if (_wutime64([path UTF16String], &times) != 0)



		@throw [OFSetItemAttributesFailedException
		    exceptionWithURL: URL
			  attributes: attributes











		     failedAttribute: of_file_attribute_key_modification_date





			       errNo: errno];


#else
	struct timeval times[2] = {
		{
			.tv_sec = (time_t)timeInterval,
			.tv_usec =
			    (int)((timeInterval - times[0].tv_sec) * 1000)
		},







>
|
|
|
|

|
>
>
>
|
|
|
>
>
>
>
>
>
>
>
>
>
>
|
>
>
>
>
>
|
>
>







611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
- (void)of_setModificationDate: (OFDate *)date
		   ofItemAtURL: (OFURL *)URL
		    attributes: (of_file_attributes_t)attributes
{
	of_time_interval_t timeInterval = date.timeIntervalSince1970;
	OFString *path = URL.fileSystemRepresentation;
#ifdef OF_WINDOWS
	if (func__wutime64 != NULL) {
		struct __utimbuf64 times = {
			(__time64_t)timeInterval,
			(__time64_t)timeInterval
		};

		if (func__wutime64([path UTF16String], &times) != 0) {
			of_file_attribute_key_t failedAttribute =
			    of_file_attribute_key_modification_date;

			@throw [OFSetItemAttributesFailedException
			    exceptionWithURL: URL
				  attributes: attributes
			     failedAttribute: failedAttribute
				       errNo: errno];
		}
	} else {
		struct _utimbuf times = {
			(time_t)timeInterval,
			(time_t)timeInterval
		};

		if (_wutime([path UTF16String], &times) != 0) {
			of_file_attribute_key_t failedAttribute =
			    of_file_attribute_key_modification_date;

			@throw [OFSetItemAttributesFailedException
			    exceptionWithURL: URL
				  attributes: attributes
			     failedAttribute: failedAttribute
				       errNo: errno];
		}
	}
#else
	struct timeval times[2] = {
		{
			.tv_sec = (time_t)timeInterval,
			.tv_usec =
			    (int)((timeInterval - times[0].tv_sec) * 1000)
		},