windows, file-or-directory-modify-seconds, can't find errno set to ENOENT

25 views
Skip to first unread message

Wayne Harris

unread,
Nov 1, 2019, 1:59:04 PM11/1/19
to racket users
I have a function called ``older-than-days?'' which produces true if a
path is older than a number of days. (Source code at the end of the
message.)

rac...@util.rkt> (older-than-days? 30 "c:/autoexec.bat")
#t

On Windows, if I give it a non-existent file, I can't seem to get an
errno set to ENOENT.

--8<---------------cut here---------------start------------->8---
rac...@util.rkt> (older-than-days? 30 "c:/whatever")
file-or-directory-modify-seconds: error getting file/directory time
path: c:/whatever
system error: Unknown error; errno=-1
#f
rac...@util.rkt>
--8<---------------cut here---------------end--------------->8---

I looked at the source code for file-or-directory-modify-seconds at

https://github.com/racket/racket/blob/136ea767e2f76aa3785ebd1ca214411cc68b4533/racket/src/rktio/rktio_fs.c#L1034

Here's the relevant passage:

--8<---------------cut here---------------start------------->8---
rktio_timestamp_t *rktio_get_file_modify_seconds(rktio_t *rktio, const char *file)
{
#ifdef RKTIO_SYSTEM_WINDOWS
rktio_timestamp_t *secs;
if (UNC_stat(rktio, file, NULL, NULL, NULL, &secs, NULL, NULL, -1))
return secs;
return NULL;
#else
[...]
#endif
--8<---------------cut here---------------end--------------->8---

(I couldn't locate UNC_stat. Where is it?) I guessed it some stat()
C function was called. Microsoft seems to say stat does set errno in
cases such as ENOENT.

https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/stat-functions?view=vs-2019

So I expected to see errno set to ENOENT in that example above.

Can you educate me on this? Thank you.

--8<---------------cut here---------------start------------->8---
My ``older-than-days?'' source code:

(define (older-than-days? days path)
(define timeline-mark (- (current-seconds) (* days 24 3600)))
(define path-mark
(with-handlers
([exn:fail:filesystem?
(lambda (e) ;; where's my errno?
(displayln (exn-message e))
+inf.0)])
(file-or-directory-modify-seconds path)))
(< path-mark timeline-mark))
--8<---------------cut here---------------end--------------->8---

Matthew Flatt

unread,
Nov 1, 2019, 4:46:45 PM11/1/19
to Wayne Harris, racket users
Racket uses the native Windows API for filesystem operations, so it
generally creates exceptions with a 'windows value in the `errno` field
instead of a 'posix value. The `UNC_stat` function is also implemented
in "rktio_fs.c".

But you don't seem to be getting a 'windows error, either, and I
haven't been able to replicate that behavior. Just to make sure I'm
trying with a relevant version, which version of Racket are you
running?
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/racket-users/lwnybyElykkp86XSbAc727heWInydkLJ
> UXrd65QEXw1OMznXm0sEQBwoHJV9e5hpA2N4sX5uoODUptUhmCGHHZIv7hqWZtwFCB1lUSDDzJQ%3D%
> 40protonmail.com.

Wayne Harris

unread,
Nov 1, 2019, 5:40:13 PM11/1/19
to Matthew Flatt, racket users
‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐
On Friday, November 1, 2019 5:46 PM, Matthew Flatt <mfl...@cs.utah.edu> wrote:

> Racket uses the native Windows API for filesystem operations, so it
> generally creates exceptions with a 'windows value in the `errno` field
> instead of a 'posix value. The `UNC_stat` function is also implemented
> in "rktio_fs.c".
>
> But you don't seem to be getting a 'windows error, either, and I
> haven't been able to replicate that behavior. Just to make sure I'm
> trying with a relevant version, which version of Racket are you
> running?

Hm. That must be the difference. I'm running Racket v6.6 which must
really old for the speed of life nowadays.

Wayne Harris

unread,
Nov 1, 2019, 10:10:04 PM11/1/19
to Wayne Harris, Matthew Flatt, racket users
‐‐‐‐‐‐‐ Original Message ‐‐‐‐‐‐‐
Yes, that's an old problem. Sorry about that.

Welcome to Racket v7.0.
racket@> ,enter "c:/somewhere/util.rkt"
rac...@util.rkt> (older-than-days? 30 "c:/whatever")
file-or-directory-modify-seconds: error getting file/directory time
path: c:/whatever
system error: The system cannot find the specified file.; errid=2
#f
rac...@util.rkt>

Reply all
Reply to author
Forward
0 new messages