1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
|
$NetBSD: patch-cy,v 1.3 2006/01/05 18:25:57 joerg Exp $
--- lib/libxview/textsw/txt_file.c.orig 1993-06-29 07:17:48.000000000 +0200
+++ lib/libxview/textsw/txt_file.c 2004-09-30 22:24:41.000000000 +0200
@@ -18,6 +18,7 @@ static char sccsid[] = "@(#)txt_file
#include <xview_private/txt_impl.h>
#include <xview_private/ev_impl.h>
#include <xview_private/txt_18impl.h>
+#include <limits.h>
#ifdef SVR4
#include <dirent.h>
#include <string.h>
@@ -45,13 +46,27 @@ static char sccsid[] = "@(#)txt_file
extern CHAR *STRCAT();
extern CHAR *STRNCAT();
-#ifdef SVR4
+
+#if (defined(SVR4) || (__NetBSD_Version__ >= 103080000)) || defined(__DragonFly__)
+#define GETCWD
+#endif
+
+#ifdef GETCWD
extern char *getcwd();
#else
extern char *getwd();
-#endif /* SVR4 */
+#endif /* GETCWD */
+#if (defined(BSD) && (BSD >= 199306))
+#if defined(__DragonFly__) || (defined(__NetBSD__) && __NetBSD_Version__ > 103080000)
+#include <errno.h>
+#else
+extern int errno, sys_nerr;
+extern const char *const sys_errlist[];
+#endif
+#else
extern int errno, sys_nerr;
extern char *sys_errlist[];
+#endif
Pkg_private int textsw_change_directory();
Pkg_private void textsw_display(), textsw_display_view_margins();
@@ -314,7 +329,11 @@ textsw_load_selection(folio, locx, locy,
register int locx, locy;
int no_cd;
{
+#ifdef NAME_MAX
+ CHAR filename[NAME_MAX];
+#else
CHAR filename[MAXNAMLEN];
+#endif
register int result;
if (textsw_get_selection_as_filename(
@@ -354,21 +373,21 @@ textsw_full_pathname(name)
}
#ifdef OW_I18N
-#ifdef SVR4
+#ifdef GETCWD
if (getcwd(pathname_mb, MAXPATHLEN) == 0)
#else
if (getwd(pathname_mb) == 0)
-#endif /* SVR4 */
+#endif /* GETCWD */
return (0);
(void) mbstowcs(pathname, pathname_mb, MAXPATHLEN-1);
#else /* OW_I18N */
-#ifdef SVR4
+#ifdef GETCWD
if (getcwd(pathname, MAXPATHLEN) == 0)
#else
if (getwd(pathname) == 0)
-#endif /* SVR4 */
+#endif /* GETCWD */
return (0);
#endif /* OW_I18N */
@@ -459,8 +478,13 @@ textsw_load_file(abstract, filename, res
int reset_views;
int locx, locy;
{
+#ifdef NAME_MAX
+ char notice_msg_buf[NAME_MAX + 100];
+ CHAR scratch_name[NAME_MAX];
+#else
char notice_msg_buf[MAXNAMLEN + 100];
CHAR scratch_name[MAXNAMLEN];
+#endif
int result;
Es_status status;
Es_handle new_esh;
@@ -546,7 +570,11 @@ textsw_load_file_quietly(abstract, filen
int reset_views;
int locx, locy;
{
+#ifdef NAME_MAX
+ CHAR scratch_name[NAME_MAX];
+#else
CHAR scratch_name[MAXNAMLEN];
+#endif
Es_status status;
Es_handle new_esh;
Es_index start_at;
@@ -587,7 +615,11 @@ textsw_save_store_common(folio, output_n
CHAR *output_name;
int reload;
{
+#ifdef NAME_MAX
+ CHAR scratch_name[NAME_MAX];
+#else
CHAR scratch_name[MAXNAMLEN];
+#endif
Es_handle new_esh;
register Es_handle output;
Es_status result;
@@ -604,9 +636,16 @@ textsw_save_store_common(folio, output_n
es_destroy(output);
if (folio->checkpoint_name) {
#ifdef OW_I18N
+#ifdef NAME_MAX
+ char temp_mb[NAME_MAX];
+
+ (void) wcstombs(temp_mb, folio->checkpoint_name, NAME_MAX);
+#else
char temp_mb[MAXNAMLEN];
(void) wcstombs(temp_mb, folio->checkpoint_name, MAXNAMLEN);
+#endif
+
if (unlink(temp_mb) == -1) { /* } for match */
#else
if (unlink(folio->checkpoint_name) == -1) {
@@ -733,7 +772,11 @@ textsw_save_internal(folio, error_buf, l
int locx, locy; /* Currently unused */
{
Pkg_private Es_handle es_file_make_backup();
+#ifdef NAME_MAX
+ CHAR original_name[NAME_MAX], *name;
+#else
CHAR original_name[MAXNAMLEN], *name;
+#endif
register char *msg;
Es_handle backup, original = ES_NULL;
int status;
@@ -826,10 +869,16 @@ Was the file edited with another editor?
textsw_save_store_common(folio, original_name, RELOAD)) {
case ES_SUCCESS: {
#ifdef OW_I18N
+#ifdef NAME_MAX
+ char original_name_mb[NAME_MAX];
+
+ (void) wcstombs(original_name_mb, original_name, NAME_MAX);
+#else
char original_name_mb[MAXNAMLEN];
(void) wcstombs(original_name_mb, original_name, MAXNAMLEN);
#endif
+#endif
(void) es_destroy(original);
textsw_notify(folio->first_view,
#ifdef OW_I18N
@@ -868,7 +917,11 @@ textsw_save(abstract, locx, locy)
Textsw abstract;
int locx, locy;
{
+#ifdef NAME_MAX
+ char error_buf[NAME_MAX];
+#else
char error_buf[MAXNAMLEN + 100];
+#endif
Es_status status;
Textsw_view_handle view = VIEW_ABS_TO_REP(abstract);
@@ -969,7 +1022,11 @@ textsw_cd(textsw, locx, locy)
Textsw_folio textsw;
int locx, locy;
{
+#ifdef NAME_MAX
+ CHAR buf[NAME_MAX];
+#else
CHAR buf[MAXNAMLEN];
+#endif
if (0 == textsw_get_selection_as_filename(
textsw, buf, SIZEOF(buf), locx, locy)) {
@@ -988,15 +1045,27 @@ textsw_get_from_file(view, filename, pri
int fd;
Es_status status;
Textsw_status result = TEXTSW_STATUS_CANNOT_INSERT_FROM_FILE;
+#ifdef NAME_MAX
+ CHAR buf[NAME_MAX];
+#else
CHAR buf[MAXNAMLEN];
+#endif
if (!TXTSW_IS_READ_ONLY(folio) && ((int)STRLEN(filename) > 0)) {
STRCPY(buf, filename);
#ifdef OW_I18N
+#ifdef NAME_MAX
+ if (textsw_expand_filename(folio, buf, NAME_MAX, -1, -1) == 0) {/* } */
+ char buf_mb[NAME_MAX];
+
+ (void) wcstombs(buf_mb, buf, NAME_MAX);
+#else
if (textsw_expand_filename(folio, buf, MAXNAMLEN, -1, -1) == 0) {/* } */
char buf_mb[MAXNAMLEN];
(void) wcstombs(buf_mb, buf, MAXNAMLEN);
+#endif
+
if ((fd = open(buf_mb, 0)) >= 0) { /* } for match */
textsw_implicit_commit(folio);
#else
@@ -1034,9 +1103,15 @@ textsw_file_stuff(view, locx, locy)
{
Textsw_folio folio = FOLIO_FOR_VIEW(view);
int fd;
+#ifdef NAME_MAX
+ CHAR buf[NAME_MAX];
+ char msg[NAME_MAX + 100], *sys_msg;
+ char notice_msg1[NAME_MAX + 100];
+#else
CHAR buf[MAXNAMLEN];
char msg[MAXNAMLEN + 100], *sys_msg;
char notice_msg1[MAXNAMLEN + 100];
+#endif
char *notice_msg2;
Es_status status;
int cannot_open = 0;
@@ -1047,9 +1122,15 @@ textsw_file_stuff(view, locx, locy)
if (0 == textsw_get_selection_as_filename(
folio, buf, SIZEOF(buf), locx, locy)) {
#ifdef OW_I18N
+#ifdef NAME_MAX
+ char buf_mb[NAME_MAX];
+
+ (void) wcstombs(buf_mb, buf, NAME_MAX);
+#else
char buf_mb[MAXNAMLEN];
(void) wcstombs(buf_mb, buf, MAXNAMLEN);
+#endif
if ((fd = open(buf_mb, 0)) < 0) { /* } for match */
#else
if ((fd = open(buf, 0)) < 0) {
@@ -1141,8 +1222,13 @@ textsw_file_stuff_from_str(view, buf, lo
{
Textsw_folio folio = FOLIO_FOR_VIEW(view);
int fd;
+#ifdef NAME_MAX
+ char msg[NAME_MAX + 100], *sys_msg;
+ char notice_msg1[NAME_MAX + 100];
+#else
char msg[MAXNAMLEN + 100], *sys_msg;
char notice_msg1[MAXNAMLEN + 100];
+#endif
char *notice_msg2;
Es_status status;
int cannot_open = 0;
@@ -1150,9 +1236,15 @@ textsw_file_stuff_from_str(view, buf, lo
Xv_Notice text_notice;
Frame frame;
#ifdef OW_I18N
+#ifdef NAME_MAX
+ char buf_mb[NAME_MAX];
+
+ (void) wcstombs(buf_mb, buf, NAME_MAX);
+#else
char buf_mb[MAXNAMLEN];
(void) wcstombs(buf_mb, buf, MAXNAMLEN);
+#endif
if ((fd = open(buf_mb, 0)) < 0) { /* } for match */
#else
if ((fd = open(buf, 0)) < 0) {
@@ -1245,9 +1337,15 @@ textsw_store_init(textsw, filename)
{
struct stat stat_buf;
#ifdef OW_I18N
+#ifdef NAME_MAX
+ char filename_mb[NAME_MAX];
+
+ (void) wcstombs(filename_mb, filename, NAME_MAX);
+#else
char filename_mb[MAXNAMLEN];
(void) wcstombs(filename_mb, filename, MAXNAMLEN);
+#endif
if (stat(filename_mb, &stat_buf) == 0) { /* } for match */
#else
if (stat(filename, &stat_buf) == 0) {
@@ -1310,10 +1408,16 @@ textsw_process_store_error(textsw, filen
case ES_CANNOT_OVERWRITE:
#ifdef OW_I18N
{
+#ifdef NAME_MAX
+ char filename_mb[NAME_MAX];
+
+ (void) wcstombs(filename_mb, filename, NAME_MAX);
+#else
char filename_mb[MAXNAMLEN];
(void) wcstombs(filename_mb, filename, MAXNAMLEN);
#endif
+#endif
frame = FRAME_FROM_FOLIO_OR_VIEW(textsw);
text_notice = (Xv_Notice)xv_get(frame,
XV_KEY_DATA, text_notice_key,
@@ -1465,9 +1569,12 @@ textsw_store_file_internal(abstract, fil
if (status == ES_SUCCESS) {
if (textsw->state & TXTSW_STORE_CHANGES_FILE) {
#ifdef OW_I18N
- char filename_mbs[MAXNAMLEN];
+#ifdef NAME_MAX
+ char filename_mbs[NAME_MAX];
- (void) wcstombs(filename_mbs, filename, MAXNAMLEN);
+ (void) wcstombs(filename_mbs, filename, NAME_MAX);
+#else
+#endif
textsw_notify(textsw->first_view,
TEXTSW_ACTION_LOADED_FILE, filename_mbs,
TEXTSW_ACTION_LOADED_FILE_WCS, filename, 0);
@@ -1491,9 +1598,15 @@ textsw_store_file(abstract, filename, lo
int locx, locy;
{
#ifdef OW_I18N
+#ifdef NAME_MAX
+ CHAR filename_wcs[NAME_MAX];
+
+ (void) mbstowcs(filename_wcs, filename, NAME_MAX);
+#else
CHAR filename_wcs[MAXNAMLEN];
(void) mbstowcs(filename_wcs, filename, MAXNAMLEN);
+#endif
return (textsw_store_file_internal(abstract, filename_wcs, locx, locy));
#else
return (textsw_store_file_internal(abstract, filename, locx, locy));
@@ -1516,7 +1629,11 @@ textsw_store_to_selection(textsw, locx,
Textsw_folio textsw;
int locx, locy;
{
+#ifdef NAME_MAX
+ CHAR filename[NAME_MAX];
+#else
CHAR filename[MAXNAMLEN];
+#endif
if (textsw_get_selection_as_filename(
textsw, filename, SIZEOF(filename), locx, locy))
@@ -1545,11 +1662,19 @@ textsw_reset_2(abstract, locx, locy, pre
#endif /* SVR4 */
Pkg_private Es_handle es_mem_create();
Es_handle piece_esh, old_original_esh, new_original_esh;
+ char *temp_name;
+#ifdef NAME_MAX
+#ifdef OW_I18N
+ CHAR *name, save_name[NAME_MAX], scratch_name[NAME_MAX];
+#else
+ char *name, save_name[NAME_MAX], scratch_name[NAME_MAX];
+#endif
+#else
#ifdef OW_I18N
CHAR *name, save_name[MAXNAMLEN], scratch_name[MAXNAMLEN];
- char *temp_name;
#else
- char *name, save_name[MAXNAMLEN], scratch_name[MAXNAMLEN], *temp_name;
+ char *name, save_name[MAXNAMLEN], scratch_name[MAXNAMLEN];
+#endif
#endif
int status;
Textsw_folio folio = FOLIO_FOR_VIEW(VIEW_ABS_TO_REP(abstract));
@@ -1591,7 +1716,11 @@ textsw_reset_2(abstract, locx, locy, pre
(char *) window_get(abstract, TEXTSW_TEMP_FILENAME);
if (temp_name)
#ifdef OW_I18N
+#ifdef NAME_MAX
+ (void) mbstowcs(save_name, temp_name, NAME_MAX);
+#else
(void) mbstowcs(save_name, temp_name, MAXNAMLEN);
+#endif
#else
(void) STRCPY(save_name, temp_name);
#endif
@@ -2150,7 +2279,11 @@ textsw_post_error(folio_or_view, locx, l
int locx, locy; /* Unused */
char *msg1, *msg2;
{
+#ifdef NAME_MAX
+ char buf[NAME_MAX + 1000];
+#else
char buf[MAXNAMLEN + 1000];
+#endif
int size_to_use = sizeof(buf);
Frame frame;
Xv_Notice text_notice;
@@ -2226,8 +2359,13 @@ textsw_change_directory(textsw, filename
CHAR *full_pathname_wc;
char filename[MAXPATHLEN];
#endif
+#ifdef NAME_MAX
+ char msg[NAME_MAX + 100];
+ char notice_msg[NAME_MAX + 100];
+#else
char msg[MAXNAMLEN + 100];
char notice_msg[MAXNAMLEN + 100];
+#endif
struct stat stat_buf;
int result = 0;
int notice_result;
@@ -2402,8 +2540,13 @@ textsw_checkpoint_internal(folio)
CHAR *name;
if (textsw_file_name(folio, &name) != 0)
return (ES_CANNOT_GET_NAME);
+#ifdef NAME_MAX
+ if ((folio->checkpoint_name = (CHAR *) MALLOC(NAME_MAX)) == 0)
+ return (ES_CANNOT_GET_NAME);
+#else
if ((folio->checkpoint_name = (CHAR *) MALLOC(MAXNAMLEN)) == 0)
return (ES_CANNOT_GET_NAME);
+#endif
#ifdef OW_I18N
(void) SPRINTF(folio->checkpoint_name, "%ws%%%%", name);
#else
@@ -2773,7 +2916,11 @@ textsw_invalid_data_notice(view, filenam
int flag;
{
Xv_Notice text_notice;
+#ifdef NAME_MAX
+ char notice_msg[NAME_MAX + 300];
+#else
char notice_msg[MAXNAMLEN + 300];
+#endif
Frame frame = FRAME_FROM_FOLIO_OR_VIEW(view);
if (flag) {
|