1 /*
2                                   NETWIB
3                              Network library
4                 Copyright(c) 1999-2010 Laurent Constantin
5                                   -----
6 
7   Main server   : http://www.laurentconstantin.com/
8   Backup server : http://laurentconstantin.free.fr/
9   [my current email address is on the web servers]
10 
11                                   -----
12   This file is part of Netwib.
13 
14   Netwib is free software: you can redistribute it and/or modify
15   it under the terms of the GNU General Public License version 3
16   as published by the Free Software Foundation.
17 
18   Netwib is distributed in the hope that it will be useful,
19   but WITHOUT ANY WARRANTY; without even the implied warranty of
20   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21   GNU General Public License for more details (http://www.gnu.org/).
22 
23 ------------------------------------------------------------------------
24 */
25 
26 #include <netwib/inc/maininc.h>
27 
28 /*-------------------------------------------------------------*/
netwib_unix_symlink(netwib_constbuf * ppathname,netwib_constbuf * plinkname)29 netwib_err netwib_unix_symlink(netwib_constbuf *ppathname,
30                                netwib_constbuf *plinkname)
31 #if defined NETWIBDEF_SYSNAME_Unix
32 {
33   netwib_string pathname, linkname;
34   int reti;
35 
36   netwib__constbuf_ref_string(ppathname, pathname, bufstorage,
37                               netwib_unix_symlink(&bufstorage, plinkname));
38   netwib__constbuf_ref_string(plinkname, linkname, bufstorage,
39                               netwib_unix_symlink(ppathname, &bufstorage));
40 
41   reti = symlink(pathname, linkname);
42   if (reti == -1) {
43     return(NETWIB_ERR_FUSYMLINK);
44   }
45 
46   return(NETWIB_ERR_OK);
47 }
48 #elif defined NETWIBDEF_SYSNAME_Windows
49 {
50   ppathname = ppathname; /* for compiler warning */
51   plinkname = plinkname; /* for compiler warning */
52   return(NETWIB_ERR_LONOTSUPPORTED);
53 }
54 #else
55  #error "Unknown value for NETWIBDEF_SYSNAME"
56 #endif
57 
58 /*-------------------------------------------------------------*/
netwib_unix_readlink(netwib_constbuf * plinkname,netwib_buf * ppathname)59 netwib_err netwib_unix_readlink(netwib_constbuf *plinkname,
60                                 netwib_buf *ppathname)
61 #if defined NETWIBDEF_SYSNAME_Unix
62 {
63   netwib_byte array[1024];
64   netwib_buf buf;
65   netwib_string linkname;
66   netwib_uint32 savedsize;
67   netwib_err ret;
68   int reti;
69 
70   netwib__constbuf_ref_string(plinkname, linkname, bufstorage,
71                               netwib_unix_readlink(&bufstorage, ppathname));
72 
73   reti = readlink(linkname, (netwib_string)array, sizeof(array));
74   if (reti == -1) {
75     return(NETWIB_ERR_FUREADLINK);
76   }
77 
78   /* save position in case of error */
79   savedsize = netwib__buf_ref_data_size(ppathname);
80 
81   netwib_er(netwib_buf_init_ext_arrayfilled(array, reti, &buf));
82   ret = netwib_path_canon(&buf, ppathname);
83   if (ret != NETWIB_ERR_OK) {
84     ppathname->endoffset = ppathname->beginoffset + savedsize;
85     netwib_er(netwib_buf_append_data(array, reti, ppathname));
86   }
87 
88   return(NETWIB_ERR_OK);
89 }
90 #elif defined NETWIBDEF_SYSNAME_Windows
91 {
92   plinkname = plinkname; /* for compiler warning */
93   ppathname = ppathname; /* for compiler warning */
94   return(NETWIB_ERR_LONOTSUPPORTED);
95 }
96 #else
97  #error "Unknown value for NETWIBDEF_SYSNAME"
98 #endif
99