vio_local_win: Properly set errno in case of error happened.
authorKlaas Freitag <freitag@owncloud.com>
Wed, 9 Sep 2015 12:10:23 +0000 (14:10 +0200)
committerKlaas Freitag <freitag@owncloud.com>
Wed, 9 Sep 2015 12:10:23 +0000 (14:10 +0200)
Without a proper errno value, the calling function can not detect
the kind of problem.

csync/src/vio/csync_vio_local_win.c

index 8f55356ab29f3f4b08b8ba992767debace2ca40e..7cd9ea8254efba8020d318409b0fc88024628007 100644 (file)
@@ -74,6 +74,12 @@ csync_vio_handle_t *csync_vio_local_opendir(const char *name) {
   }
 
   if (!dirname || handle->hFind == INVALID_HANDLE_VALUE) {
+      int retcode = GetLastError();
+      if( retcode == ERROR_FILE_NOT_FOUND ) {
+          errno = ENOENT;
+      } else {
+          errno = EACCES;
+      }
       SAFE_FREE(handle);
       return NULL;
   }
@@ -99,6 +105,9 @@ int csync_vio_local_closedir(csync_vio_handle_t *dhandle) {
   // FindClose returns non-zero on success
   if( FindClose(handle->hFind) != 0 ) {
       rc = 0;
+  } else {
+      // error case, set errno
+      errno = EBADF;
   }
 
   SAFE_FREE(handle->path);
@@ -117,7 +126,8 @@ csync_vio_file_stat_t *csync_vio_local_readdir(csync_vio_handle_t *dhandle) {
   errno = 0;
   file_stat = csync_vio_file_stat_new();
   if (file_stat == NULL) {
-    goto err;
+      errno = ENOMEM;
+      goto err;
   }
   file_stat->fields = CSYNC_VIO_FILE_STAT_FIELDS_NONE;