/[meta-cvs]/meta-cvs/F-83F0E6A90D5BBCDFB58440970E850925.c
ViewVC logotype

Contents of /meta-cvs/F-83F0E6A90D5BBCDFB58440970E850925.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3.2.1 - (show annotations)
Sun Aug 25 16:07:05 2002 UTC (11 years, 7 months ago) by kaz
Branch: symlink-branch
CVS Tags: symlink-branch~merged-to-HEAD-0
Changes since 1.3: +37 -0 lines
File MIME type: text/plain
Support for symbolic links added to the mapping module.  The format of
the map file has changed to accomodate this.  The new format of the
list entries is (:keyword "id" "path" ...) where the keyword is either
:file or :symlink (for now, extensible obviously), "id" is a unique
identifier (for regular files, it is their MCVS/F-* name) and "path" is
the sandbox path. Other things can follow; for symlinks, there is a
string representing the symlink target.  Internally, a new data type
called mapping-entry is used; this is a struct. So the functions which
read and write maps now convert between the struct format and the above
format.

* code/unix-bindings/unix.lisp (unix-funcs:readlink): New function.

* code/unix-bindings/impl.c (impl_readlink): New function.

* code/clisp-unix.lisp (readlink-error): New condition.
(initialize-instance readlink-error): New method for
initialize-instance generic function, specialized for readlink-error.
(readlink): New function.

* code/mapping.lisp (mapping-entry): New struct, with slots
file, id, path and target.
(mapping-same-object-p): Renamed to mapping-same-id-p.
(mapping-object-lookup, mapping-moved-p): Unused functions removed.
(mapping-extract-paths, mapping-lookup, mapping-prefix-lookup,
mapping-prefix-matches, mapping-same-path-p, mapping-rename-files,
mapping-removed-files): Functions updated to use the new data
structure.
(mapping-dupe-checks): Rewritten for new data structure, and to
use hashes rather than silly sorting.
(mapping-convert-old-style-in, mapping-convert-in,
mapping-convert-out): New functions.
(mapping-read): Handle new and old style representations,
handle conversion to internal representation.
(mapping-write): Convert to new-style external representation
before writing out.
(mapping-synchronize): Handle symbolic links. If a link is missing,
create it. If it's present but different from what it should be,
erase it and re-create it.
(mapping-update): Use new data structure. Handle symbolic links.

* code/remove.lisp (mcvs-remove): Refer to new function
name, mapping-same-id-p.
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <errno.h>
5 #include <dirent.h>
6 #include <unistd.h>
7 #include <sys/types.h>
8 #include <sys/stat.h>
9
10 /*
11 * Null pointer test
12 */
13
14 int impl_null_pointer_p(void *ptr)
15 {
16 return ptr == 0;
17 }
18
19 /*
20 * <errno.h> stuff
21 */
22
23 int impl_get_errno(void)
24 {
25 return errno;
26 }
27
28 int impl_set_errno(int value)
29 {
30 return errno = value;
31 }
32
33 /*
34 * <dirent.h> stuff
35 */
36
37 typedef struct {
38 unsigned long d_ino;
39 char d_name[1024];
40 } impl_dirent;
41
42 impl_dirent *impl_readdir(DIR *dir)
43 {
44 static impl_dirent dw;
45 struct dirent *de = readdir(dir);
46 if (de != 0) {
47 strncpy(dw.d_name, de->d_name, sizeof dw.d_name - 1);
48 dw.d_ino = de->d_ino;
49 return &dw;
50 }
51 return 0;
52 }
53
54 /*
55 * <unistd.h> stuff
56 */
57
58 char *impl_readlink(const char *path)
59 {
60 size_t size = 256;
61 char *str = malloc(size);
62 char *temp;
63
64 if (str == 0)
65 goto bail;
66
67 for (;;) {
68 int result = readlink(path, str, size);
69 if (result == -1)
70 goto bail;
71 if (result < size) {
72 str[result] = 0;
73 break;
74 }
75 if (size * 2 < size)
76 goto bail;
77 size *= 2;
78 if ((temp = realloc(str, size)) == 0)
79 goto bail;
80 str = temp;
81 }
82
83 /* No need to realloc to actual size, since CLISP will free this anyway */
84 return str;
85
86 bail:
87 free(str);
88 return 0;
89 }
90
91 /*
92 * <sys/stat.h> stuff
93 */
94
95 struct impl_stat {
96 unsigned long dev;
97 unsigned long ino;
98 unsigned long mode;
99 unsigned int nlink;
100 unsigned int uid;
101 unsigned int gid;
102 unsigned long rdev;
103 unsigned long blksize;
104 unsigned long blocks;
105 unsigned long atime;
106 unsigned long mtime;
107 unsigned long ctime;
108 };
109
110 static void stat_to_impl(struct impl_stat *out, const struct stat *in)
111 {
112 out->dev = in->st_dev;
113 out->ino = in->st_ino;
114 out->mode = in->st_mode;
115 out->nlink = in->st_nlink;
116 out->uid = in->st_uid;
117 out->gid = in->st_gid;
118 out->rdev = in->st_rdev;
119 out->blksize = in->st_blksize;
120 out->blocks = in->st_blocks;
121 out->atime = in->st_atime;
122 out->mtime = in->st_mtime;
123 out->ctime = in->st_ctime;
124 }
125
126 #define IMPL_STAT(FUNC, ARGTYPE) \
127 int impl_ ## FUNC(ARGTYPE arg, struct impl_stat *buf) \
128 { \
129 struct stat sbuf; \
130 int retval = FUNC(arg, &sbuf); \
131 if (retval == 0) \
132 stat_to_impl(buf, &sbuf); \
133 return retval; \
134 }
135
136 IMPL_STAT(stat, const char *)
137 IMPL_STAT(lstat, const char *)
138 IMPL_STAT(fstat, int)
139
140 /*
141 * <unistd.h> -- getcwd
142 */
143
144 const char *impl_getcwd(void)
145 {
146 size_t size = 256;
147 char *str = malloc(size);
148 char *temp;
149
150 if (str == 0)
151 goto bail;
152
153 while (getcwd(str, size) == 0) {
154 if (size * 2 < size)
155 goto bail;
156 size *= 2;
157 if ((temp = realloc(str, size)) == 0)
158 goto bail;
159 str = temp;
160 }
161
162 /* No need to realloc to actual size, since CLISP will free this anyway */
163 return str;
164
165 bail:
166 free(str);
167 return 0;
168 }

  ViewVC Help
Powered by ViewVC 1.1.5