dirfd: set errno upon failure
authorJim Meyering <meyering@redhat.com>
Tue, 3 Feb 2009 06:47:07 +0000 (07:47 +0100)
committerJim Meyering <meyering@redhat.com>
Wed, 4 Feb 2009 13:50:07 +0000 (14:50 +0100)
* lib/dirfd.c: Include <errno.h>.
Set errno to ENOTSUP when returning -1.
* modules/dirfd (Depends-on): Add errno.
Suggested by John Kodis <kodis@comcast.net>.

lib/dirfd.c
modules/dirfd

index 3458e99b203bc9764b745e71dd3e3dc9a9e845e5..81993c502c1f89c71304d7390c9df8240a86d782 100644 (file)
@@ -1,6 +1,6 @@
 /* dirfd.c -- return the file descriptor associated with an open DIR*
 
-   Copyright (C) 2001, 2006, 2008 Free Software Foundation, Inc.
+   Copyright (C) 2001, 2006, 2008-2009 Free Software Foundation, Inc.
 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
 #include <config.h>
 
 #include <dirent.h>
+#include <errno.h>
 
 int
 dirfd (DIR const *dir_p)
 {
-  return DIR_TO_FD (dir_p);
+  int fd = DIR_TO_FD (dir_p);
+  if (fd == -1)
+    errno = ENOTSUP;
+  return fd;
 }
index 25450bd6e4d654811b8c0a5b875bf632a8c00fe2..42ff4d7a0f0f9c61c3827284d865c8eaceca90ca 100644 (file)
@@ -7,6 +7,7 @@ m4/dirfd.m4
 
 Depends-on:
 dirent
+errno
 extensions
 
 configure.ac: