Some more configure checks for headers
[deb_libnfs.git] / lib / libnfs.c
index 2f47ba8f4245a95d3161cac6b0578518ef10d2f2..c322c377b15d5a858da2e084c0e8aeeb03ee11b8 100644 (file)
 /*
  * High level api to nfs filesystems
  */
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#ifdef AROS
+#include "aros_compat.h"
+#endif
+
 #ifdef WIN32
 #include "win32_compat.h"
-#define DllExport
-#else
-#include <strings.h>
-#include <sys/statvfs.h>
+#endif
+
+#ifdef HAVE_UTIME_H
 #include <utime.h>
-#include <unistd.h>
-#endif/*WIN32*/
+#endif
+
+#ifdef ANDROID
+#define statvfs statfs
+#endif
 
 #define _GNU_SOURCE
 
+#ifdef HAVE_UNISTD_H
+#include <unistd.h>
+#endif
+
+#ifdef HAVE_SYS_VFS_H
+#include <sys/vfs.h>
+#endif
+
+#ifdef HAVE_SYS_STATVFS_H
+#include <sys/statvfs.h>
+#endif
+
+#ifdef HAVE_NETINET_IN_H
+#include <netinet/in.h>
+#endif
+
+#ifdef HAVE_STRINGS_H
+#include <strings.h>
+#endif
+
 #include <stdio.h>
 #include <stdarg.h>
 #include <stdlib.h>
@@ -38,6 +68,7 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
+#include "libnfs-zdr.h"
 #include "libnfs.h"
 #include "libnfs-raw.h"
 #include "libnfs-raw-mount.h"
@@ -112,7 +143,7 @@ struct nfs_mcb_data {
 static int nfs_lookup_path_async_internal(struct nfs_context *nfs, struct nfs_cb_data *data, struct nfs_fh3 *fh);
 
 
-void nfs_set_auth(struct nfs_context *nfs, AUTH *auth)
+void nfs_set_auth(struct nfs_context *nfs, struct AUTH *auth)
 {
        rpc_set_auth(nfs->rpc, auth);
 }
@@ -637,8 +668,8 @@ static int nfs_lookuppath_async(struct nfs_context *nfs, const char *path, nfs_c
 {
        struct nfs_cb_data *data;
 
-       if (path[0] != '/') {
-               rpc_set_error(nfs->rpc, "Pathname is not absulute %s", path);
+       if (path[0] != 0 && path[0] != '/') {
+               rpc_set_error(nfs->rpc, "Pathname is not absolute %s", path);
                return -1;
        }
 
@@ -1652,10 +1683,10 @@ static void nfs_create_2_cb(struct rpc_context *rpc, int status, void *command_d
        }
        memset(nfsfh, 0, sizeof(struct nfsfh));
 
-       /* steal the filehandle */
-       nfsfh->fh.data.data_len = data->fh.data.data_len;
-       nfsfh->fh.data.data_val = data->fh.data.data_val;
-       data->fh.data.data_val = NULL;
+       /* copy the filehandle */
+       nfsfh->fh.data.data_len = res->LOOKUP3res_u.resok.object.data.data_len;
+       nfsfh->fh.data.data_val = malloc(nfsfh->fh.data.data_len);
+       memcpy(nfsfh->fh.data.data_val, res->LOOKUP3res_u.resok.object.data.data_val, nfsfh->fh.data.data_len);
 
        data->cb(0, nfs, nfsfh, data->private_data);
        free_nfs_cb_data(data);
@@ -1708,7 +1739,6 @@ static int nfs_creat_continue_internal(struct nfs_context *nfs, struct nfs_cb_da
 
        str = &str[strlen(str) + 1];
 
-
        memset(&args, 0, sizeof(CREATE3args));
        args.where.dir.data.data_len = data->fh.data.data_len;
        args.where.dir.data.data_val = data->fh.data.data_val;
@@ -1744,7 +1774,7 @@ int nfs_creat_async(struct nfs_context *nfs, const char *path, int mode, nfs_cb
        }
        *ptr = 0;
 
-       /* new_path now points to the parent directory,  and beyond the nul terminateor is the new directory to create */
+       /* new_path now points to the parent directory,  and beyond the nul terminator is the new directory to create */
        if (nfs_lookuppath_async(nfs, new_path, cb, private_data, nfs_creat_continue_internal, new_path, free, mode) != 0) {
                rpc_set_error(nfs->rpc, "Out of memory: failed to start parsing the path components");
                return -1;
@@ -2412,10 +2442,12 @@ static void nfs_statvfs_1_cb(struct rpc_context *rpc, int status, void *command_
        svfs.f_bavail  = res->FSSTAT3res_u.resok.abytes/4096;
        svfs.f_files   = res->FSSTAT3res_u.resok.tfiles;
        svfs.f_ffree   = res->FSSTAT3res_u.resok.ffiles;
+#if !defined(ANDROID)
        svfs.f_favail  = res->FSSTAT3res_u.resok.afiles;
        svfs.f_fsid    = 0;
        svfs.f_flag    = 0;
        svfs.f_namemax = 256;
+#endif
 
        data->cb(0, nfs, &svfs, data->private_data);
        free_nfs_cb_data(data);
@@ -3417,7 +3449,7 @@ uint64_t nfs_get_readmax(struct nfs_context *nfs)
  */
 uint64_t nfs_get_writemax(struct nfs_context *nfs)
 {
-       /* Some XDR libraries can not marshall PDUs bigger than this */
+       /* Some ZDR libraries can not marshall PDUs bigger than this */
         if (nfs->writemax < 32768) {
                return nfs->writemax;
        }