comparison src/sysdep.c @ 2526:902d5bd9b75c

[xemacs-hg @ 2005-01-28 02:36:11 by ben] Support symlinks under Windows nt.c, fileio.c: Fix sync comments. config.h.in, dired-msw.c, emacs.c, event-msw.c, fileio.c, glyphs.c, lisp.h, nt.c, process-nt.c, realpath.c, sound.c, symsinit.h, sysdep.c, sysfile.h, syswindows.h, win32.c: Add support for treating shortcuts under Windows as symbolic links. Enabled with mswindows-shortcuts-are-links (t by default). Rewrite lots of places to use PATHNAME_CONVERT_OUT, which is moved to sysfile.h. Add PATHNAME_RESOLVE_LINKS, which only does things under Windows. Add profiling section for expand_file_name calls. nt.c, sysdep.c: Unicode-ize. realpath.c: Renamed from readlink_and_correct_case. Fix some problems with Windows implementation due to incorrect understanding of workings of the function. sound.c, ntplay.c, sound.h: Rename play_sound_file to nt_play_sound_file and pass internally-formatted data to it to avoid converting out and back again. text.h: is_c -> is_ascii.
author ben
date Fri, 28 Jan 2005 02:36:28 +0000
parents 3d8143fc88e1
children e20ee26d2313
comparison
equal deleted inserted replaced
2525:52f00344a629 2526:902d5bd9b75c
626 if (sh == 0) 626 if (sh == 0)
627 sh = egetenv ("SHELL"); 627 sh = egetenv ("SHELL");
628 if (sh == 0) 628 if (sh == 0)
629 sh = (Ibyte *) "sh"; 629 sh = (Ibyte *) "sh";
630 630
631 C_STRING_TO_EXTERNAL (sh, shext, Qfile_name); 631 PATHNAME_CONVERT_OUT (sh, shext);
632 632
633 UNGCPRO; 633 UNGCPRO;
634 634
635 #ifdef WIN32_NATIVE 635 #ifdef WIN32_NATIVE
636 636
637 if (str) 637 if (str)
638 qxe_chdir (str); 638 qxe_chdir (str);
639 639
640 /* Waits for process completion */ 640 /* Waits for process completion */
641 if (_spawnlp (_P_WAIT, shext, shext, NULL) != 0) 641 if (XEUNICODE_P ?
642 _wspawnlp (_P_WAIT, (const wchar_t *) shext,
643 (const wchar_t *) shext, NULL) != 0 :
644 _spawnlp (_P_WAIT, shext, shext, NULL) != 0)
642 report_process_error ("Can't spawn subshell", Qunbound); 645 report_process_error ("Can't spawn subshell", Qunbound);
643 else 646 else
644 return; /* we're done, no need to wait for termination */ 647 return; /* we're done, no need to wait for termination */
645 648
646 #else /* not WIN32_NATIVE */ 649 #else /* not WIN32_NATIVE */
2535 2538
2536 /************************************************************************/ 2539 /************************************************************************/
2537 /* Encapsulations of system calls */ 2540 /* Encapsulations of system calls */
2538 /************************************************************************/ 2541 /************************************************************************/
2539 2542
2540 /* The documentation in VC++ claims that the pathname library functions
2541 accept strings in the current locale-specific encoding, but that's
2542 false, because they just call the native Win32 routines directly, which
2543 always use the system-default encoding (which is what Qmswindows_tstr
2544 will give us when not XEUNICODE_P). */
2545 #ifdef WIN32_NATIVE
2546 #define PATHNAME_CONVERT_OUT(path, pathout) C_STRING_TO_TSTR (path, pathout)
2547 #else
2548 #define PATHNAME_CONVERT_OUT(path, pathout) \
2549 C_STRING_TO_EXTERNAL (path, pathout, Qfile_name)
2550 #endif
2551
2552 /***************** low-level calls ****************/ 2543 /***************** low-level calls ****************/
2553 2544
2554 /* 2545 /*
2555 * On USG systems the system calls are INTERRUPTIBLE by signals 2546 * On USG systems the system calls are INTERRUPTIBLE by signals
2556 * that the user program has elected to catch. Thus the system call 2547 * that the user program has elected to catch. Thus the system call
3178 { 3169 {
3179 /* if system does not have symbolic links, it does not have lstat. 3170 /* if system does not have symbolic links, it does not have lstat.
3180 In that case, use ordinary stat instead. */ 3171 In that case, use ordinary stat instead. */
3181 #ifndef S_IFLNK 3172 #ifndef S_IFLNK
3182 return qxe_stat (path, buf); 3173 return qxe_stat (path, buf);
3174 #elif defined (WIN32_NATIVE)
3175 if (mswindows_shortcuts_are_symlinks)
3176 {
3177 /* We want to resolve the directory component and leave the rest
3178 alone. */
3179 Ibyte *dirend = find_end_of_directory_component (path, qxestrlen (path));
3180 Bytecount len;
3181
3182 if (dirend != path)
3183 {
3184 Ibyte *resdir;
3185 Ichar lastch;
3186 DECLARE_EISTRING (resname);
3187 DECLARE_EISTRING (dir);
3188
3189 eicpy_raw (dir, path, dirend - path);
3190 PATHNAME_RESOLVE_LINKS (eidata (dir), resdir);
3191 eicpy_rawz (resname, resdir);
3192 lastch = eigetch_char (resname, eicharlen (resname) - 1);
3193 if (!IS_DIRECTORY_SEP (lastch))
3194 eicat_ch (resname, '\\');
3195 eicat_rawz (resname, dirend);
3196 path = eidata (resname);
3197 }
3198
3199 /* However, if what we are trying to stat is a link, we need to add
3200 the .LNK so that the actual file is statted. */
3201 len = qxestrlen (path);
3202 if (len > 4 && qxestrcasecmp_ascii (path + len - 4, ".LNK"))
3203 {
3204 DECLARE_EISTRING (name2);
3205 Ibyte *resolved;
3206
3207 eicpy_rawz (name2, path);
3208 eicat_ascii (name2, ".LNK");
3209 resolved = mswindows_read_link (eidata (name2));
3210 if (resolved)
3211 {
3212 xfree (resolved, Ibyte *);
3213 return mswindows_stat (eidata (name2), buf);
3214 }
3215 }
3216 }
3217
3218 return mswindows_stat (path, buf);
3183 #else 3219 #else
3184 Extbyte *pathout; 3220 Extbyte *pathout;
3185 PATHNAME_CONVERT_OUT (path, pathout); 3221 PATHNAME_CONVERT_OUT (path, pathout);
3186 return lstat (pathout, buf); 3222 return lstat (pathout, buf);
3187 #endif 3223 #endif
3225 3261
3226 int 3262 int
3227 qxe_stat (const Ibyte *path, struct stat *buf) 3263 qxe_stat (const Ibyte *path, struct stat *buf)
3228 { 3264 {
3229 #ifdef WIN32_NATIVE 3265 #ifdef WIN32_NATIVE
3230 return mswindows_stat (path, buf); 3266 Ibyte *resolved;
3267 PATHNAME_RESOLVE_LINKS (path, resolved);
3268 return mswindows_stat (resolved, buf);
3231 #else /* not WIN32_NATIVE */ 3269 #else /* not WIN32_NATIVE */
3232 Extbyte *pathout; 3270 Extbyte *pathout;
3233 PATHNAME_CONVERT_OUT (path, pathout); 3271 PATHNAME_CONVERT_OUT (path, pathout);
3234 return stat (pathout, buf); 3272 return stat (pathout, buf);
3235 #endif /* WIN32_NATIVE */ 3273 #endif /* WIN32_NATIVE */