Initial original import from: fuse-2.4.2-2.fc4
[captive.git] / src / client / lufs / captivefs-misc.c
1 /* $Id$
2  * lufs interface module misc functions for libcaptive
3  * Copyright (C) 2003 Jan Kratochvil <project-captive@jankratochvil.net>
4  * 
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; exactly version 2 of June 1991 is required
8  * 
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  * 
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17  */
18
19
20 #include "config.h"
21
22 #include "captivefs-misc.h"     /* self */
23 #include <glib/gmessages.h>
24 #include "captivefs-vfs.h"
25
26 #include <captive/client-vfs.h>
27
28
29 /* module-scope lock for _any_ libcaptive access */
30 G_LOCK_DEFINE(libcaptive);
31
32
33 /* Resolve a link (if the info was not added to the dir cache when 
34  * reading the parent dir)
35  */
36 int captivefs_readlink(struct captivefs_vfs *captivefs_vfs,const char *link,char *buf,int buflen)
37 {
38         g_return_val_if_fail(captivefs_vfs_validate(captivefs_vfs),-1);
39         g_return_val_if_fail(link!=NULL,-1);
40         g_return_val_if_fail(buf!=NULL,-1);
41         g_return_val_if_fail(buflen>0,-1);
42
43         if (captivefs_vfs->options.debug_messages)
44                 g_log(G_LOG_DOMAIN,G_LOG_LEVEL_DEBUG,"captivefs_readlink: link=%s,buflen=%d",link,buflen);
45
46         return -1;      /* unsupported by W32 */
47 }
48
49
50 /* Create a link
51  */
52 int captivefs_link(struct captivefs_vfs *captivefs_vfs,const char *target,const char *lnk)
53 {
54         g_return_val_if_fail(captivefs_vfs_validate(captivefs_vfs),-1);
55         g_return_val_if_fail(target!=NULL,-1);
56         g_return_val_if_fail(lnk!=NULL,-1);
57
58         if (captivefs_vfs->options.debug_messages)
59                 g_log(G_LOG_DOMAIN,G_LOG_LEVEL_DEBUG,"captivefs_link: target=%s,lnk=%s",target,lnk);
60
61         return -1;      /* unsupported by W32 */
62 }
63
64
65 /* Create a symlink
66  */
67 int captivefs_symlink(struct captivefs_vfs *captivefs_vfs,const char *target,const char *link)
68 {
69         g_return_val_if_fail(captivefs_vfs_validate(captivefs_vfs),-1);
70         g_return_val_if_fail(target!=NULL,-1);
71         g_return_val_if_fail(link!=NULL,-1);
72
73         if (captivefs_vfs->options.debug_messages)
74                 g_log(G_LOG_DOMAIN,G_LOG_LEVEL_DEBUG,"captivefs_symlink: target=%s,link=%s",target,link);
75
76         return -1;      /* unsupported by W32 */
77 }
78
79
80 char *captivefs_filename_to_utf8_malloc_errorchecking(const char *name)
81 {
82 GError *error;
83 char *r;
84
85         g_return_val_if_fail(name!=NULL,NULL);
86
87         error=NULL;
88         r=g_filename_to_utf8(
89                         name,   /* opsysstring */
90                         -1,     /* len; '\0'-terminated */
91                         NULL,   /* bytes_read */
92                         NULL,   /* bytes_written */
93                         &error);        /* error */
94         if (error) {
95                 g_log(G_LOG_DOMAIN,G_LOG_LEVEL_WARNING,
96                                 _("captivefs %s(): name=\"%s\": %s (see locale(7) and mount(8) environment variables)"),
97                                 "g_filename_to_utf8",name,error->message);
98                 g_clear_error(&error);
99                 }
100         return r;
101 }
102
103
104 char *captivefs_filename_from_utf8_malloc_errorchecking(const char *name)
105 {
106 GError *error;
107 char *r;
108
109         g_return_val_if_fail(name!=NULL,NULL);
110
111         error=NULL;
112         r=g_filename_from_utf8(
113                         name,   /* utf8string */
114                         -1,     /* len; '\0'-terminated */
115                         NULL,   /* bytes_read */
116                         NULL,   /* bytes_written */
117                         &error);        /* error */
118         if (error) {
119                 g_log(G_LOG_DOMAIN,G_LOG_LEVEL_WARNING,"captivefs %s(): name=\"%s\"; g_get_charset()=\"%s\", %s: %s",
120                                 "g_filename_from_utf8",name,charset,
121                                 _("see environment variables - locale(7), mount(8) and locale(1) commands \"locale\" and \"locale -a\""),
122                                 error->message);
123                 g_clear_error(&error);
124                 }
125         return r;
126 }