$NetBSD$
--- fusesmb.c.orig	2006-05-04 23:02:43.000000000 +0300
+++ fusesmb.c	2007-04-12 13:09:45.000000000 +0300
@@ -34,7 +34,9 @@
 #include <fcntl.h>
 #include <dirent.h>
 #include <sys/param.h>
+#ifdef HAVE_SYS_VFS_H
 #include <sys/vfs.h>
+#endif
 #include <pthread.h>
 #include <libsmbclient.h>
 #include <time.h>
@@ -57,6 +59,8 @@
 static SMBCCTX *ctx, *rwd_ctx;
 pthread_t cleanup_thread;
 
+char envhome[MAXPATHLEN];
+
 /*
  * Hash for storing files/directories that were not found, an optimisation
  * for programs like konqueror and freevo that do a lot of lookups:
@@ -166,7 +170,7 @@
         }
 
         char cachefile[1024];
-        snprintf(cachefile, 1024, "%s/.smb/fusesmb.cache", getenv("HOME"));
+        snprintf(cachefile, 1024, "%s/.smb/fusesmb.cache", envhome);
         struct stat st;
         memset(&st, 0, sizeof(struct stat));
 
@@ -252,7 +256,9 @@
 
 static int fusesmb_getattr(const char *path, struct stat *stbuf)
 {
-    char smb_path[MY_MAXPATHLEN] = "smb:/", buf[MY_MAXPATHLEN], cache_file[1024];
+    char smb_path[MY_MAXPATHLEN] = "smb:/",
+	 buf[MY_MAXPATHLEN],
+	 cache_file[1024];
     int path_exists = 0;
     FILE *fp;
     struct stat cache;
@@ -261,7 +267,7 @@
     /* Check the cache for valid workgroup, hosts and shares */
     if (slashcount(path) <= 3)
     {
-        snprintf(cache_file, 1024, "%s/.smb/fusesmb.cache", getenv("HOME"));
+        snprintf(cache_file, 1024, "%s/.smb/fusesmb.cache", envhome);
 
         if (strlen(path) == 1 && path[0] == '/')
             path_exists = 1;
@@ -399,7 +405,7 @@
     if (slashcount(path) <= 2)
     {
         /* Listing Workgroups */
-        snprintf(cache_file, 1024, "%s/.smb/fusesmb.cache", getenv("HOME"));
+        snprintf(cache_file, 1024, "%s/.smb/fusesmb.cache", envhome);
         fp = fopen(cache_file, "r");
         if (!fp)
             return -ENOENT;
@@ -750,12 +756,12 @@
     return 0;
 }
 
-static int fusesmb_statfs(const char *path, struct statfs *fst)
+static int fusesmb_statfs(const char *path, struct statvfs *fst)
 {
     /* Returning stat of local filesystem, call is too expensive */
     (void)path;
-    memset(fst, 0, sizeof(struct statfs));
-    if (statfs("/", fst) != 0)
+    memset(fst, 0, sizeof(struct statvfs));
+    if (statvfs("/", fst) != 0)
         return -errno;
     return 0;
 }
@@ -979,7 +985,8 @@
     /* Check if the directory for smbcache exists and if not so create it */
 
     char cache_path[1024];
-    snprintf(cache_path, 1024, "%s/.smb/", getenv("HOME"));
+    getenv_r("HOME", envhome, MAXPATHLEN);
+    snprintf(cache_path, 1024, "%s/.smb/", envhome);
     struct stat st;
     if (-1 == stat(cache_path, &st))
     {
@@ -1001,7 +1008,7 @@
     }
 
     char configfile[1024];
-    snprintf(configfile, 1024, "%s/.smb/fusesmb.conf", getenv("HOME"));
+    snprintf(configfile, 1024, "%s/.smb/fusesmb.conf", envhome);
     if (-1 == stat(configfile, &st))
     {
         if (errno != ENOENT)
@@ -1086,9 +1093,11 @@
     notfound_cache = hash_create(HASHCOUNT_T_MAX, NULL, NULL);
     if (notfound_cache == NULL)
         exit(EXIT_FAILURE);
-
+#ifdef __NetBSD__
+    fuse_main(argc, argv, &fusesmb_oper);
+#else
     fuse_main(my_argc, my_argv, &fusesmb_oper);
-
+#endif
     smbc_free_context(ctx, 1);
     smbc_free_context(rwd_ctx, 1);
 
