This source file includes following definitions.
- fchdir_unwind
- chdir_to_default_directory
- conv_filename_to_w32_unicode
- conv_filename_from_w32_unicode
- syms_of_cygw32
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 #include "cygw32.h"
21 #include "character.h"
22 #include "buffer.h"
23 #include <unistd.h>
24 #include <fcntl.h>
25
26 static void
27 fchdir_unwind (int dir_fd)
28 {
29 (void) fchdir (dir_fd);
30 (void) close (dir_fd);
31 }
32
33 static void
34 chdir_to_default_directory (void)
35 {
36 Lisp_Object new_cwd;
37 int old_cwd_fd = emacs_open (".", O_RDONLY | O_DIRECTORY, 0);
38
39 if (old_cwd_fd == -1)
40 error ("could not open current directory: %s", strerror (errno));
41
42 record_unwind_protect_int (fchdir_unwind, old_cwd_fd);
43
44 new_cwd = Funhandled_file_name_directory (
45 Fexpand_file_name (build_string ("."), Qnil));
46 if (!STRINGP (new_cwd))
47 new_cwd = build_string ("/");
48
49 if (chdir (SSDATA (ENCODE_FILE (new_cwd))))
50 error ("could not chdir: %s", strerror (errno));
51 }
52
53 static Lisp_Object
54 conv_filename_to_w32_unicode (Lisp_Object in, int absolute_p)
55 {
56 ssize_t converted_len;
57 Lisp_Object converted;
58 unsigned flags;
59 specpdl_ref count = SPECPDL_INDEX ();
60
61 chdir_to_default_directory ();
62
63 flags = CCP_POSIX_TO_WIN_W;
64 if (!absolute_p) {
65 flags |= CCP_RELATIVE;
66 }
67
68 in = ENCODE_FILE (in);
69
70 converted_len = cygwin_conv_path (flags, SDATA (in), NULL, 0);
71 if (converted_len < 2)
72 error ("cygwin_conv_path: %s", strerror (errno));
73
74 converted = make_uninit_string (converted_len - 1);
75 if (cygwin_conv_path (flags, SDATA (in),
76 SDATA (converted), converted_len))
77 error ("cygwin_conv_path: %s", strerror (errno));
78
79 return unbind_to (count, converted);
80 }
81
82 static Lisp_Object
83 conv_filename_from_w32_unicode (const wchar_t* in, int absolute_p)
84 {
85 ssize_t converted_len;
86 Lisp_Object converted;
87 unsigned flags;
88 specpdl_ref count = SPECPDL_INDEX ();
89
90 chdir_to_default_directory ();
91
92 flags = CCP_WIN_W_TO_POSIX;
93 if (!absolute_p) {
94 flags |= CCP_RELATIVE;
95 }
96
97 converted_len = cygwin_conv_path (flags, in, NULL, 0);
98 if (converted_len < 1)
99 error ("cygwin_conv_path: %s", strerror (errno));
100
101 converted = make_uninit_string (converted_len - 1 );
102 if (cygwin_conv_path (flags, in, SDATA (converted), converted_len))
103 error ("cygwin_conv_path: %s", strerror (errno));
104
105 return unbind_to (count, DECODE_FILE (converted));
106 }
107
108 DEFUN ("cygwin-convert-file-name-to-windows",
109 Fcygwin_convert_file_name_to_windows,
110 Scygwin_convert_file_name_to_windows,
111 1, 2, 0,
112 doc:
113
114 )
115 (Lisp_Object file, Lisp_Object absolute_p)
116 {
117 return from_unicode (
118 conv_filename_to_w32_unicode (file, NILP (absolute_p) ? 0 : 1));
119 }
120
121 DEFUN ("cygwin-convert-file-name-from-windows",
122 Fcygwin_convert_file_name_from_windows,
123 Scygwin_convert_file_name_from_windows,
124 1, 2, 0,
125 doc:
126
127 )
128 (Lisp_Object file, Lisp_Object absolute_p)
129 {
130 return conv_filename_from_w32_unicode (to_unicode (file, &file),
131 NILP (absolute_p) ? 0 : 1);
132 }
133
134 void
135 syms_of_cygw32 (void)
136 {
137 defsubr (&Scygwin_convert_file_name_from_windows);
138 defsubr (&Scygwin_convert_file_name_to_windows);
139 }