Mercurial > hg > xemacs-beta
comparison src/filelock.c @ 867:804517e16990
[xemacs-hg @ 2002-06-05 09:54:39 by ben]
Textual renaming: text/char names
abbrev.c, alloc.c, buffer.c, buffer.h, bytecode.c, callint.c, casefiddle.c, casetab.c, charset.h, chartab.c, chartab.h, cmds.c, console-gtk.h, console-msw.c, console-msw.h, console-stream.c, console-tty.c, console-x.c, console-x.h, console.h, data.c, device-msw.c, device-x.c, dialog-msw.c, dired-msw.c, dired.c, doc.c, doprnt.c, editfns.c, eldap.c, emodules.c, eval.c, event-Xt.c, event-gtk.c, event-msw.c, event-stream.c, event-unixoid.c, events.c, events.h, file-coding.c, file-coding.h, fileio.c, filelock.c, fns.c, font-lock.c, frame-gtk.c, frame-msw.c, frame-x.c, frame.c, glyphs-eimage.c, glyphs-msw.c, glyphs-x.c, glyphs.c, glyphs.h, gpmevent.c, gui-x.c, gui-x.h, gui.c, gui.h, hpplay.c, indent.c, insdel.c, insdel.h, intl-win32.c, keymap.c, line-number.c, line-number.h, lisp-disunion.h, lisp-union.h, lisp.h, lread.c, lrecord.h, lstream.c, lstream.h, md5.c, menubar-msw.c, menubar-x.c, menubar.c, minibuf.c, mule-ccl.c, mule-charset.c, mule-coding.c, mule-wnnfns.c, ndir.h, nt.c, objects-gtk.c, objects-gtk.h, objects-msw.c, objects-tty.c, objects-x.c, objects.c, objects.h, postgresql.c, print.c, process-nt.c, process-unix.c, process.c, procimpl.h, realpath.c, redisplay-gtk.c, redisplay-msw.c, redisplay-output.c, redisplay-tty.c, redisplay-x.c, redisplay.c, redisplay.h, regex.c, search.c, select-common.h, select-gtk.c, select-x.c, sound.h, symbols.c, syntax.c, syntax.h, sysdep.c, sysdep.h, sysdir.h, sysfile.h, sysproc.h, syspwd.h, systime.h, syswindows.h, termcap.c, tests.c, text.c, text.h, toolbar-common.c, tooltalk.c, ui-gtk.c, unexnt.c, unicode.c, win32.c: Text/char naming rationalization.
[a] distinguish between "charptr" when it refers to operations on
the pointer itself and when it refers to operations on text; and
[b] use consistent naming for everything referring to internal
format, i.e.
Itext == text in internal format
Ibyte == a byte in such text
Ichar == a char as represented in internal character format
thus e.g.
set_charptr_emchar -> set_itext_ichar
The pre and post tags on either side of this change are:
pre-internal-format-textual-renaming
post-internal-format-textual-renaming
See the Internals Manual for details of exactly how this was done,
how to handle the change in your workspace, etc.
author | ben |
---|---|
date | Wed, 05 Jun 2002 09:58:45 +0000 |
parents | 84762348c6f9 |
children | a8d8f419b459 |
comparison
equal
deleted
inserted
replaced
866:613552a02607 | 867:804517e16990 |
---|---|
76 | 76 |
77 /* Here is the structure that stores information about a lock. */ | 77 /* Here is the structure that stores information about a lock. */ |
78 | 78 |
79 typedef struct | 79 typedef struct |
80 { | 80 { |
81 Intbyte *user; | 81 Ibyte *user; |
82 Intbyte *host; | 82 Ibyte *host; |
83 pid_t pid; | 83 pid_t pid; |
84 } lock_info_type; | 84 } lock_info_type; |
85 | 85 |
86 /* When we read the info back, we might need this much more, | 86 /* When we read the info back, we might need this much more, |
87 enough for decimal representation plus null. */ | 87 enough for decimal representation plus null. */ |
91 #define FREE_LOCK_INFO(i) do { xfree ((i).user); xfree ((i).host); } while (0) | 91 #define FREE_LOCK_INFO(i) do { xfree ((i).user); xfree ((i).host); } while (0) |
92 | 92 |
93 /* Write the name of the lock file for FN into LFNAME. Length will be | 93 /* Write the name of the lock file for FN into LFNAME. Length will be |
94 that of FN plus two more for the leading `.#' plus one for the null. */ | 94 that of FN plus two more for the leading `.#' plus one for the null. */ |
95 #define MAKE_LOCK_NAME(lock, file) \ | 95 #define MAKE_LOCK_NAME(lock, file) \ |
96 (lock = (Intbyte *) ALLOCA (XSTRING_LENGTH (file) + 2 + 1), \ | 96 (lock = (Ibyte *) ALLOCA (XSTRING_LENGTH (file) + 2 + 1), \ |
97 fill_in_lock_file_name (lock, file)) | 97 fill_in_lock_file_name (lock, file)) |
98 | 98 |
99 static void | 99 static void |
100 fill_in_lock_file_name (Intbyte *lockfile, Lisp_Object fn) | 100 fill_in_lock_file_name (Ibyte *lockfile, Lisp_Object fn) |
101 { | 101 { |
102 Intbyte *file_name = XSTRING_DATA (fn); | 102 Ibyte *file_name = XSTRING_DATA (fn); |
103 Intbyte *p; | 103 Ibyte *p; |
104 Bytecount dirlen; | 104 Bytecount dirlen; |
105 | 105 |
106 for (p = file_name + XSTRING_LENGTH (fn) - 1; | 106 for (p = file_name + XSTRING_LENGTH (fn) - 1; |
107 p > file_name && !IS_ANY_SEP (p[-1]); | 107 p > file_name && !IS_ANY_SEP (p[-1]); |
108 p--) | 108 p--) |
119 /* Lock the lock file named LFNAME. | 119 /* Lock the lock file named LFNAME. |
120 If FORCE is nonzero, we do so even if it is already locked. | 120 If FORCE is nonzero, we do so even if it is already locked. |
121 Return 1 if successful, 0 if not. */ | 121 Return 1 if successful, 0 if not. */ |
122 | 122 |
123 static int | 123 static int |
124 lock_file_1 (Intbyte *lfname, int force) | 124 lock_file_1 (Ibyte *lfname, int force) |
125 { | 125 { |
126 /* Does not GC. */ | 126 /* Does not GC. */ |
127 int err; | 127 int err; |
128 Intbyte *lock_info_str; | 128 Ibyte *lock_info_str; |
129 Intbyte *host_name; | 129 Ibyte *host_name; |
130 Intbyte *user_name = user_login_name (NULL); | 130 Ibyte *user_name = user_login_name (NULL); |
131 | 131 |
132 if (user_name == NULL) | 132 if (user_name == NULL) |
133 user_name = (Intbyte *) ""; | 133 user_name = (Ibyte *) ""; |
134 | 134 |
135 if (STRINGP (Vsystem_name)) | 135 if (STRINGP (Vsystem_name)) |
136 host_name = XSTRING_DATA (Vsystem_name); | 136 host_name = XSTRING_DATA (Vsystem_name); |
137 else | 137 else |
138 host_name = (Intbyte *) ""; | 138 host_name = (Ibyte *) ""; |
139 | 139 |
140 lock_info_str = | 140 lock_info_str = |
141 (Intbyte *) ALLOCA (qxestrlen (user_name) + qxestrlen (host_name) | 141 (Ibyte *) ALLOCA (qxestrlen (user_name) + qxestrlen (host_name) |
142 + LOCK_PID_MAX + 5); | 142 + LOCK_PID_MAX + 5); |
143 | 143 |
144 qxesprintf (lock_info_str, "%s@%s.%d", user_name, host_name, qxe_getpid ()); | 144 qxesprintf (lock_info_str, "%s@%s.%d", user_name, host_name, qxe_getpid ()); |
145 | 145 |
146 err = qxe_symlink (lock_info_str, lfname); | 146 err = qxe_symlink (lock_info_str, lfname); |
157 1 if another process owns it (and set OWNER (if non-null) to info), | 157 1 if another process owns it (and set OWNER (if non-null) to info), |
158 2 if the current process owns it, | 158 2 if the current process owns it, |
159 or -1 if something is wrong with the locking mechanism. */ | 159 or -1 if something is wrong with the locking mechanism. */ |
160 | 160 |
161 static int | 161 static int |
162 current_lock_owner (lock_info_type *owner, Intbyte *lfname) | 162 current_lock_owner (lock_info_type *owner, Ibyte *lfname) |
163 { | 163 { |
164 /* Does not GC. */ | 164 /* Does not GC. */ |
165 int len, ret; | 165 int len, ret; |
166 int local_owner = 0; | 166 int local_owner = 0; |
167 Intbyte *at, *dot; | 167 Ibyte *at, *dot; |
168 Intbyte *lfinfo = 0; | 168 Ibyte *lfinfo = 0; |
169 int bufsize = 50; | 169 int bufsize = 50; |
170 /* Read arbitrarily-long contents of symlink. Similar code in | 170 /* Read arbitrarily-long contents of symlink. Similar code in |
171 file-symlink-p in fileio.c. */ | 171 file-symlink-p in fileio.c. */ |
172 do | 172 do |
173 { | 173 { |
174 bufsize *= 2; | 174 bufsize *= 2; |
175 lfinfo = (Intbyte *) xrealloc (lfinfo, bufsize); | 175 lfinfo = (Ibyte *) xrealloc (lfinfo, bufsize); |
176 len = qxe_readlink (lfname, lfinfo, bufsize); | 176 len = qxe_readlink (lfname, lfinfo, bufsize); |
177 } | 177 } |
178 while (len >= bufsize); | 178 while (len >= bufsize); |
179 | 179 |
180 /* If nonexistent lock file, all is well; otherwise, got strange error. */ | 180 /* If nonexistent lock file, all is well; otherwise, got strange error. */ |
202 if (!at || !dot) { | 202 if (!at || !dot) { |
203 xfree (lfinfo); | 203 xfree (lfinfo); |
204 return -1; | 204 return -1; |
205 } | 205 } |
206 len = at - lfinfo; | 206 len = at - lfinfo; |
207 owner->user = (Intbyte *) xmalloc (len + 1); | 207 owner->user = (Ibyte *) xmalloc (len + 1); |
208 qxestrncpy (owner->user, lfinfo, len); | 208 qxestrncpy (owner->user, lfinfo, len); |
209 owner->user[len] = 0; | 209 owner->user[len] = 0; |
210 | 210 |
211 /* The PID is everything after the last `.'. */ | 211 /* The PID is everything after the last `.'. */ |
212 owner->pid = atoi ((CIntbyte *) dot + 1); | 212 owner->pid = atoi ((CIbyte *) dot + 1); |
213 | 213 |
214 /* The host is everything in between. */ | 214 /* The host is everything in between. */ |
215 len = dot - at - 1; | 215 len = dot - at - 1; |
216 owner->host = (Intbyte *) xmalloc (len + 1); | 216 owner->host = (Ibyte *) xmalloc (len + 1); |
217 qxestrncpy (owner->host, at + 1, len); | 217 qxestrncpy (owner->host, at + 1, len); |
218 owner->host[len] = 0; | 218 owner->host[len] = 0; |
219 | 219 |
220 /* We're done looking at the link info. */ | 220 /* We're done looking at the link info. */ |
221 xfree (lfinfo); | 221 xfree (lfinfo); |
255 Return positive if some other process owns the lock, and info about | 255 Return positive if some other process owns the lock, and info about |
256 that process in CLASHER. | 256 that process in CLASHER. |
257 Return -1 if cannot lock for any other reason. */ | 257 Return -1 if cannot lock for any other reason. */ |
258 | 258 |
259 static int | 259 static int |
260 lock_if_free (lock_info_type *clasher, Intbyte *lfname) | 260 lock_if_free (lock_info_type *clasher, Ibyte *lfname) |
261 { | 261 { |
262 /* Does not GC. */ | 262 /* Does not GC. */ |
263 if (lock_file_1 ((Intbyte *) lfname, 0) == 0) | 263 if (lock_file_1 ((Ibyte *) lfname, 0) == 0) |
264 { | 264 { |
265 int locker; | 265 int locker; |
266 | 266 |
267 if (errno != EEXIST) | 267 if (errno != EEXIST) |
268 return -1; | 268 return -1; |
307 you protect things right. */ | 307 you protect things right. */ |
308 /* Somebody updated the code in this function and removed the previous | 308 /* Somebody updated the code in this function and removed the previous |
309 comment. -slb */ | 309 comment. -slb */ |
310 | 310 |
311 register Lisp_Object attack, orig_fn; | 311 register Lisp_Object attack, orig_fn; |
312 register Intbyte *lfname, *locker; | 312 register Ibyte *lfname, *locker; |
313 lock_info_type lock_info; | 313 lock_info_type lock_info; |
314 struct gcpro gcpro1, gcpro2, gcpro3; | 314 struct gcpro gcpro1, gcpro2, gcpro3; |
315 Lisp_Object old_current_buffer; | 315 Lisp_Object old_current_buffer; |
316 Lisp_Object subject_buf; | 316 Lisp_Object subject_buf; |
317 | 317 |
344 /* Return now if we have locked it, or if lock creation failed | 344 /* Return now if we have locked it, or if lock creation failed |
345 or current buffer is killed. */ | 345 or current buffer is killed. */ |
346 goto done; | 346 goto done; |
347 | 347 |
348 /* Else consider breaking the lock */ | 348 /* Else consider breaking the lock */ |
349 locker = (Intbyte *) ALLOCA (qxestrlen (lock_info.user) | 349 locker = (Ibyte *) ALLOCA (qxestrlen (lock_info.user) |
350 + qxestrlen (lock_info.host) | 350 + qxestrlen (lock_info.host) |
351 + LOCK_PID_MAX + 9); | 351 + LOCK_PID_MAX + 9); |
352 qxesprintf (locker, "%s@%s (pid %d)", lock_info.user, lock_info.host, | 352 qxesprintf (locker, "%s@%s (pid %d)", lock_info.user, lock_info.host, |
353 lock_info.pid); | 353 lock_info.pid); |
354 FREE_LOCK_INFO (lock_info); | 354 FREE_LOCK_INFO (lock_info); |
369 | 369 |
370 void | 370 void |
371 unlock_file (Lisp_Object fn) | 371 unlock_file (Lisp_Object fn) |
372 { | 372 { |
373 /* This can GC */ | 373 /* This can GC */ |
374 register Intbyte *lfname; | 374 register Ibyte *lfname; |
375 struct gcpro gcpro1; | 375 struct gcpro gcpro1; |
376 | 376 |
377 GCPRO1 (fn); | 377 GCPRO1 (fn); |
378 | 378 |
379 fn = Fexpand_file_name (fn, Qnil); | 379 fn = Fexpand_file_name (fn, Qnil); |
452 t if it is locked by you, else a string of the name of the locker. | 452 t if it is locked by you, else a string of the name of the locker. |
453 */ | 453 */ |
454 (filename)) | 454 (filename)) |
455 { | 455 { |
456 Lisp_Object ret; | 456 Lisp_Object ret; |
457 register Intbyte *lfname; | 457 register Ibyte *lfname; |
458 int owner; | 458 int owner; |
459 lock_info_type locker; | 459 lock_info_type locker; |
460 struct gcpro gcpro1; | 460 struct gcpro gcpro1; |
461 | 461 |
462 GCPRO1 (filename); | 462 GCPRO1 (filename); |