sys/vfs/hammer2: Remove unused HMNT2_NOAUTOSNAP
[dragonfly.git] / contrib / less / filename.c
blob7c3ccd2e97a573ca1527fffd940518f92e017682
1 /*
2 * Copyright (C) 1984-2019 Mark Nudelman
4 * You may distribute under the terms of either the GNU General Public
5 * License or the Less License, as specified in the README file.
7 * For more information, see the README file.
8 */
12 * Routines to mess around with filenames (and files).
13 * Much of this is very OS dependent.
16 #include "less.h"
17 #include "lglob.h"
18 #if MSDOS_COMPILER
19 #include <dos.h>
20 #if MSDOS_COMPILER==WIN32C && !defined(_MSC_VER)
21 #include <dir.h>
22 #endif
23 #if MSDOS_COMPILER==DJGPPC
24 #include <glob.h>
25 #include <dir.h>
26 #define _MAX_PATH PATH_MAX
27 #endif
28 #endif
29 #ifdef _OSK
30 #include <rbf.h>
31 #ifndef _OSK_MWC32
32 #include <modes.h>
33 #endif
34 #endif
36 #if HAVE_STAT
37 #include <sys/stat.h>
38 #ifndef S_ISDIR
39 #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
40 #endif
41 #ifndef S_ISREG
42 #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
43 #endif
44 #endif
46 extern int force_open;
47 extern int secure;
48 extern int use_lessopen;
49 extern int ctldisp;
50 extern int utf_mode;
51 extern IFILE curr_ifile;
52 extern IFILE old_ifile;
53 #if SPACES_IN_FILENAMES
54 extern char openquote;
55 extern char closequote;
56 #endif
59 * Remove quotes around a filename.
61 public char *
62 shell_unquote(str)
63 char *str;
65 char *name;
66 char *p;
68 name = p = (char *) ecalloc(strlen(str)+1, sizeof(char));
69 if (*str == openquote)
71 str++;
72 while (*str != '\0')
74 if (*str == closequote)
76 if (str[1] != closequote)
77 break;
78 str++;
80 *p++ = *str++;
82 } else
84 char *esc = get_meta_escape();
85 int esclen = (int) strlen(esc);
86 while (*str != '\0')
88 if (esclen > 0 && strncmp(str, esc, esclen) == 0)
89 str += esclen;
90 *p++ = *str++;
93 *p = '\0';
94 return (name);
98 * Get the shell's escape character.
100 public char *
101 get_meta_escape(VOID_PARAM)
103 char *s;
105 s = lgetenv("LESSMETAESCAPE");
106 if (s == NULL)
107 s = DEF_METAESCAPE;
108 return (s);
112 * Get the characters which the shell considers to be "metacharacters".
114 static char *
115 metachars(VOID_PARAM)
117 static char *mchars = NULL;
119 if (mchars == NULL)
121 mchars = lgetenv("LESSMETACHARS");
122 if (mchars == NULL)
123 mchars = DEF_METACHARS;
125 return (mchars);
129 * Is this a shell metacharacter?
131 static int
132 metachar(c)
133 char c;
135 return (strchr(metachars(), c) != NULL);
139 * Insert a backslash before each metacharacter in a string.
141 public char *
142 shell_quote(s)
143 char *s;
145 char *p;
146 char *newstr;
147 int len;
148 char *esc = get_meta_escape();
149 int esclen = (int) strlen(esc);
150 int use_quotes = 0;
151 int have_quotes = 0;
154 * Determine how big a string we need to allocate.
156 len = 1; /* Trailing null byte */
157 for (p = s; *p != '\0'; p++)
159 len++;
160 if (*p == openquote || *p == closequote)
161 have_quotes = 1;
162 if (metachar(*p))
164 if (esclen == 0)
167 * We've got a metachar, but this shell
168 * doesn't support escape chars. Use quotes.
170 use_quotes = 1;
171 } else
174 * Allow space for the escape char.
176 len += esclen;
180 if (use_quotes)
182 if (have_quotes)
184 * We can't quote a string that contains quotes.
186 return (NULL);
187 len = (int) strlen(s) + 3;
190 * Allocate and construct the new string.
192 newstr = p = (char *) ecalloc(len, sizeof(char));
193 if (use_quotes)
195 SNPRINTF3(newstr, len, "%c%s%c", openquote, s, closequote);
196 } else
198 while (*s != '\0')
200 if (metachar(*s))
203 * Add the escape char.
205 strcpy(p, esc);
206 p += esclen;
208 *p++ = *s++;
210 *p = '\0';
212 return (newstr);
216 * Return a pathname that points to a specified file in a specified directory.
217 * Return NULL if the file does not exist in the directory.
219 static char *
220 dirfile(dirname, filename)
221 char *dirname;
222 char *filename;
224 char *pathname;
225 int len;
226 int f;
228 if (dirname == NULL || *dirname == '\0')
229 return (NULL);
231 * Construct the full pathname.
233 len = (int) (strlen(dirname) + strlen(filename) + 2);
234 pathname = (char *) calloc(len, sizeof(char));
235 if (pathname == NULL)
236 return (NULL);
237 SNPRINTF3(pathname, len, "%s%s%s", dirname, PATHNAME_SEP, filename);
239 * Make sure the file exists.
241 f = open(pathname, OPEN_READ);
242 if (f < 0)
244 free(pathname);
245 pathname = NULL;
246 } else
248 close(f);
250 return (pathname);
254 * Return the full pathname of the given file in the "home directory".
256 public char *
257 homefile(filename)
258 char *filename;
260 char *pathname;
263 * Try $HOME/filename.
265 pathname = dirfile(lgetenv("HOME"), filename);
266 if (pathname != NULL)
267 return (pathname);
268 #if OS2
270 * Try $INIT/filename.
272 pathname = dirfile(lgetenv("INIT"), filename);
273 if (pathname != NULL)
274 return (pathname);
275 #endif
276 #if MSDOS_COMPILER || OS2
278 * Look for the file anywhere on search path.
280 pathname = (char *) calloc(_MAX_PATH, sizeof(char));
281 #if MSDOS_COMPILER==DJGPPC
283 char *res = searchpath(filename);
284 if (res == 0)
285 *pathname = '\0';
286 else
287 strcpy(pathname, res);
289 #else
290 _searchenv(filename, "PATH", pathname);
291 #endif
292 if (*pathname != '\0')
293 return (pathname);
294 free(pathname);
295 #endif
296 return (NULL);
300 * Expand a string, substituting any "%" with the current filename,
301 * and any "#" with the previous filename.
302 * But a string of N "%"s is just replaced with N-1 "%"s.
303 * Likewise for a string of N "#"s.
304 * {{ This is a lot of work just to support % and #. }}
306 public char *
307 fexpand(s)
308 char *s;
310 char *fr, *to;
311 int n;
312 char *e;
313 IFILE ifile;
315 #define fchar_ifile(c) \
316 ((c) == '%' ? curr_ifile : \
317 (c) == '#' ? old_ifile : NULL_IFILE)
320 * Make one pass to see how big a buffer we
321 * need to allocate for the expanded string.
323 n = 0;
324 for (fr = s; *fr != '\0'; fr++)
326 switch (*fr)
328 case '%':
329 case '#':
330 if (fr > s && fr[-1] == *fr)
333 * Second (or later) char in a string
334 * of identical chars. Treat as normal.
336 n++;
337 } else if (fr[1] != *fr)
340 * Single char (not repeated). Treat specially.
342 ifile = fchar_ifile(*fr);
343 if (ifile == NULL_IFILE)
344 n++;
345 else
346 n += (int) strlen(get_filename(ifile));
349 * Else it is the first char in a string of
350 * identical chars. Just discard it.
352 break;
353 default:
354 n++;
355 break;
359 e = (char *) ecalloc(n+1, sizeof(char));
362 * Now copy the string, expanding any "%" or "#".
364 to = e;
365 for (fr = s; *fr != '\0'; fr++)
367 switch (*fr)
369 case '%':
370 case '#':
371 if (fr > s && fr[-1] == *fr)
373 *to++ = *fr;
374 } else if (fr[1] != *fr)
376 ifile = fchar_ifile(*fr);
377 if (ifile == NULL_IFILE)
378 *to++ = *fr;
379 else
381 strcpy(to, get_filename(ifile));
382 to += strlen(to);
385 break;
386 default:
387 *to++ = *fr;
388 break;
391 *to = '\0';
392 return (e);
396 #if TAB_COMPLETE_FILENAME
399 * Return a blank-separated list of filenames which "complete"
400 * the given string.
402 public char *
403 fcomplete(s)
404 char *s;
406 char *fpat;
407 char *qs;
409 if (secure)
410 return (NULL);
412 * Complete the filename "s" by globbing "s*".
414 #if MSDOS_COMPILER && (MSDOS_COMPILER == MSOFTC || MSDOS_COMPILER == BORLANDC)
416 * But in DOS, we have to glob "s*.*".
417 * But if the final component of the filename already has
418 * a dot in it, just do "s*".
419 * (Thus, "FILE" is globbed as "FILE*.*",
420 * but "FILE.A" is globbed as "FILE.A*").
423 char *slash;
424 int len;
425 for (slash = s+strlen(s)-1; slash > s; slash--)
426 if (*slash == *PATHNAME_SEP || *slash == '/')
427 break;
428 len = (int) strlen(s) + 4;
429 fpat = (char *) ecalloc(len, sizeof(char));
430 if (strchr(slash, '.') == NULL)
431 SNPRINTF1(fpat, len, "%s*.*", s);
432 else
433 SNPRINTF1(fpat, len, "%s*", s);
435 #else
437 int len = (int) strlen(s) + 2;
438 fpat = (char *) ecalloc(len, sizeof(char));
439 SNPRINTF1(fpat, len, "%s*", s);
441 #endif
442 qs = lglob(fpat);
443 s = shell_unquote(qs);
444 if (strcmp(s,fpat) == 0)
447 * The filename didn't expand.
449 free(qs);
450 qs = NULL;
452 free(s);
453 free(fpat);
454 return (qs);
456 #endif
459 * Try to determine if a file is "binary".
460 * This is just a guess, and we need not try too hard to make it accurate.
462 public int
463 bin_file(f)
464 int f;
466 int n;
467 int bin_count = 0;
468 char data[256];
469 char* p;
470 char* edata;
472 if (!seekable(f))
473 return (0);
474 if (lseek(f, (off_t)0, SEEK_SET) == BAD_LSEEK)
475 return (0);
476 n = read(f, data, sizeof(data));
477 if (n <= 0)
478 return (0);
479 edata = &data[n];
480 for (p = data; p < edata; )
482 if (utf_mode && !is_utf8_well_formed(p, edata-data))
484 bin_count++;
485 utf_skip_to_lead(&p, edata);
486 } else
488 LWCHAR c = step_char(&p, +1, edata);
489 if (ctldisp == OPT_ONPLUS && IS_CSI_START(c))
490 skip_ansi(&p, edata);
491 else if (binary_char(c))
492 bin_count++;
496 * Call it a binary file if there are more than 5 binary characters
497 * in the first 256 bytes of the file.
499 return (bin_count > 5);
503 * Try to determine the size of a file by seeking to the end.
505 static POSITION
506 seek_filesize(f)
507 int f;
509 off_t spos;
511 spos = lseek(f, (off_t)0, SEEK_END);
512 if (spos == BAD_LSEEK)
513 return (NULL_POSITION);
514 return ((POSITION) spos);
518 * Read a string from a file.
519 * Return a pointer to the string in memory.
521 static char *
522 readfd(fd)
523 FILE *fd;
525 int len;
526 int ch;
527 char *buf;
528 char *p;
531 * Make a guess about how many chars in the string
532 * and allocate a buffer to hold it.
534 len = 100;
535 buf = (char *) ecalloc(len, sizeof(char));
536 for (p = buf; ; p++)
538 if ((ch = getc(fd)) == '\n' || ch == EOF)
539 break;
540 if (p - buf >= len-1)
543 * The string is too big to fit in the buffer we have.
544 * Allocate a new buffer, twice as big.
546 len *= 2;
547 *p = '\0';
548 p = (char *) ecalloc(len, sizeof(char));
549 strcpy(p, buf);
550 free(buf);
551 buf = p;
552 p = buf + strlen(buf);
554 *p = ch;
556 *p = '\0';
557 return (buf);
562 #if HAVE_POPEN
565 * Execute a shell command.
566 * Return a pointer to a pipe connected to the shell command's standard output.
568 static FILE *
569 shellcmd(cmd)
570 char *cmd;
572 FILE *fd;
574 #if HAVE_SHELL
575 char *shell;
577 shell = lgetenv("SHELL");
578 if (!isnullenv(shell))
580 char *scmd;
581 char *esccmd;
584 * Read the output of <$SHELL -c cmd>.
585 * Escape any metacharacters in the command.
587 esccmd = shell_quote(cmd);
588 if (esccmd == NULL)
590 fd = popen(cmd, "r");
591 } else
593 int len = (int) (strlen(shell) + strlen(esccmd) + 5);
594 scmd = (char *) ecalloc(len, sizeof(char));
595 SNPRINTF3(scmd, len, "%s %s %s", shell, shell_coption(), esccmd);
596 free(esccmd);
597 fd = popen(scmd, "r");
598 free(scmd);
600 } else
601 #endif
603 fd = popen(cmd, "r");
606 * Redirection in `popen' might have messed with the
607 * standard devices. Restore binary input mode.
609 SET_BINARY(0);
610 return (fd);
613 #endif /* HAVE_POPEN */
617 * Expand a filename, doing any system-specific metacharacter substitutions.
619 public char *
620 lglob(filename)
621 char *filename;
623 char *gfilename;
625 filename = fexpand(filename);
626 if (secure)
627 return (filename);
629 #ifdef DECL_GLOB_LIST
632 * The globbing function returns a list of names.
634 int length;
635 char *p;
636 char *qfilename;
637 DECL_GLOB_LIST(list)
639 GLOB_LIST(filename, list);
640 if (GLOB_LIST_FAILED(list))
642 return (filename);
644 length = 1; /* Room for trailing null byte */
645 for (SCAN_GLOB_LIST(list, p))
647 INIT_GLOB_LIST(list, p);
648 qfilename = shell_quote(p);
649 if (qfilename != NULL)
651 length += strlen(qfilename) + 1;
652 free(qfilename);
655 gfilename = (char *) ecalloc(length, sizeof(char));
656 for (SCAN_GLOB_LIST(list, p))
658 INIT_GLOB_LIST(list, p);
659 qfilename = shell_quote(p);
660 if (qfilename != NULL)
662 sprintf(gfilename + strlen(gfilename), "%s ", qfilename);
663 free(qfilename);
667 * Overwrite the final trailing space with a null terminator.
669 *--p = '\0';
670 GLOB_LIST_DONE(list);
672 #else
673 #ifdef DECL_GLOB_NAME
676 * The globbing function returns a single name, and
677 * is called multiple times to walk thru all names.
679 char *p;
680 int len;
681 int n;
682 char *pfilename;
683 char *qfilename;
684 DECL_GLOB_NAME(fnd,drive,dir,fname,ext,handle)
686 GLOB_FIRST_NAME(filename, &fnd, handle);
687 if (GLOB_FIRST_FAILED(handle))
689 return (filename);
692 _splitpath(filename, drive, dir, fname, ext);
693 len = 100;
694 gfilename = (char *) ecalloc(len, sizeof(char));
695 p = gfilename;
696 do {
697 n = (int) (strlen(drive) + strlen(dir) + strlen(fnd.GLOB_NAME) + 1);
698 pfilename = (char *) ecalloc(n, sizeof(char));
699 SNPRINTF3(pfilename, n, "%s%s%s", drive, dir, fnd.GLOB_NAME);
700 qfilename = shell_quote(pfilename);
701 free(pfilename);
702 if (qfilename != NULL)
704 n = (int) strlen(qfilename);
705 while (p - gfilename + n + 2 >= len)
708 * No room in current buffer.
709 * Allocate a bigger one.
711 len *= 2;
712 *p = '\0';
713 p = (char *) ecalloc(len, sizeof(char));
714 strcpy(p, gfilename);
715 free(gfilename);
716 gfilename = p;
717 p = gfilename + strlen(gfilename);
719 strcpy(p, qfilename);
720 free(qfilename);
721 p += n;
722 *p++ = ' ';
724 } while (GLOB_NEXT_NAME(handle, &fnd) == 0);
727 * Overwrite the final trailing space with a null terminator.
729 *--p = '\0';
730 GLOB_NAME_DONE(handle);
732 #else
733 #if HAVE_POPEN
736 * We get the shell to glob the filename for us by passing
737 * an "echo" command to the shell and reading its output.
739 FILE *fd;
740 char *s;
741 char *lessecho;
742 char *cmd;
743 char *esc;
744 int len;
746 esc = get_meta_escape();
747 if (strlen(esc) == 0)
748 esc = "-";
749 esc = shell_quote(esc);
750 if (esc == NULL)
752 return (filename);
754 lessecho = lgetenv("LESSECHO");
755 if (isnullenv(lessecho))
756 lessecho = "lessecho";
758 * Invoke lessecho, and read its output (a globbed list of filenames).
760 len = (int) (strlen(lessecho) + strlen(filename) + (7*strlen(metachars())) + 24);
761 cmd = (char *) ecalloc(len, sizeof(char));
762 SNPRINTF4(cmd, len, "%s -p0x%x -d0x%x -e%s ", lessecho, openquote, closequote, esc);
763 free(esc);
764 for (s = metachars(); *s != '\0'; s++)
765 sprintf(cmd + strlen(cmd), "-n0x%x ", *s);
766 sprintf(cmd + strlen(cmd), "-- %s", filename);
767 fd = shellcmd(cmd);
768 free(cmd);
769 if (fd == NULL)
772 * Cannot create the pipe.
773 * Just return the original (fexpanded) filename.
775 return (filename);
777 gfilename = readfd(fd);
778 pclose(fd);
779 if (*gfilename == '\0')
781 free(gfilename);
782 return (filename);
785 #else
787 * No globbing functions at all. Just use the fexpanded filename.
789 gfilename = save(filename);
790 #endif
791 #endif
792 #endif
793 free(filename);
794 return (gfilename);
798 * @@@
800 public char *
801 lrealpath(path)
802 char *path;
804 #if HAVE_REALPATH
805 char rpath[PATH_MAX];
806 if (realpath(path, rpath) != NULL)
807 return (save(rpath));
808 #endif
809 return (save(path));
813 * Return number of %s escapes in a string.
814 * Return a large number if there are any other % escapes besides %s.
816 static int
817 num_pct_s(lessopen)
818 char *lessopen;
820 int num = 0;
822 while (*lessopen != '\0')
824 if (*lessopen == '%')
826 if (lessopen[1] == '%')
827 ++lessopen;
828 else if (lessopen[1] == 's')
829 ++num;
830 else
831 return (999);
833 ++lessopen;
835 return (num);
839 * See if we should open a "replacement file"
840 * instead of the file we're about to open.
842 public char *
843 open_altfile(filename, pf, pfd)
844 char *filename;
845 int *pf;
846 void **pfd;
848 #if !HAVE_POPEN
849 return (NULL);
850 #else
851 char *lessopen;
852 char *qfilename;
853 char *cmd;
854 int len;
855 FILE *fd;
856 #if HAVE_FILENO
857 int returnfd = 0;
858 #endif
860 if (!use_lessopen || secure)
861 return (NULL);
862 ch_ungetchar(-1);
863 if ((lessopen = lgetenv("LESSOPEN")) == NULL)
864 return (NULL);
865 while (*lessopen == '|')
868 * If LESSOPEN starts with a |, it indicates
869 * a "pipe preprocessor".
871 #if !HAVE_FILENO
872 error("LESSOPEN pipe is not supported", NULL_PARG);
873 return (NULL);
874 #else
875 lessopen++;
876 returnfd++;
877 #endif
879 if (*lessopen == '-')
882 * Lessopen preprocessor will accept "-" as a filename.
884 lessopen++;
885 } else
887 if (strcmp(filename, "-") == 0)
888 return (NULL);
890 if (num_pct_s(lessopen) != 1)
892 error("LESSOPEN ignored: must contain exactly one %%s", NULL_PARG);
893 return (NULL);
896 qfilename = shell_quote(filename);
897 len = (int) (strlen(lessopen) + strlen(qfilename) + 2);
898 cmd = (char *) ecalloc(len, sizeof(char));
899 SNPRINTF1(cmd, len, lessopen, qfilename);
900 free(qfilename);
901 fd = shellcmd(cmd);
902 free(cmd);
903 if (fd == NULL)
906 * Cannot create the pipe.
908 return (NULL);
910 #if HAVE_FILENO
911 if (returnfd)
913 char c;
914 int f;
917 * The first time we open the file, read one char
918 * to see if the pipe will produce any data.
919 * If it does, push the char back on the pipe.
921 f = fileno(fd);
922 SET_BINARY(f);
923 if (read(f, &c, 1) != 1)
926 * Pipe is empty.
927 * If more than 1 pipe char was specified,
928 * the exit status tells whether the file itself
929 * is empty, or if there is no alt file.
930 * If only one pipe char, just assume no alt file.
932 int status = pclose(fd);
933 if (returnfd > 1 && status == 0) {
934 *pfd = NULL;
935 *pf = -1;
936 return (save(FAKE_EMPTYFILE));
938 return (NULL);
940 ch_ungetchar(c);
941 *pfd = (void *) fd;
942 *pf = f;
943 return (save("-"));
945 #endif
946 cmd = readfd(fd);
947 pclose(fd);
948 if (*cmd == '\0')
950 * Pipe is empty. This means there is no alt file.
952 return (NULL);
953 return (cmd);
954 #endif /* HAVE_POPEN */
958 * Close a replacement file.
960 public void
961 close_altfile(altfilename, filename)
962 char *altfilename;
963 char *filename;
965 #if HAVE_POPEN
966 char *lessclose;
967 FILE *fd;
968 char *cmd;
969 int len;
971 if (secure)
972 return;
973 ch_ungetchar(-1);
974 if ((lessclose = lgetenv("LESSCLOSE")) == NULL)
975 return;
976 if (num_pct_s(lessclose) > 2)
978 error("LESSCLOSE ignored; must contain no more than 2 %%s", NULL_PARG);
979 return;
981 len = (int) (strlen(lessclose) + strlen(filename) + strlen(altfilename) + 2);
982 cmd = (char *) ecalloc(len, sizeof(char));
983 SNPRINTF2(cmd, len, lessclose, filename, altfilename);
984 fd = shellcmd(cmd);
985 free(cmd);
986 if (fd != NULL)
987 pclose(fd);
988 #endif
992 * Is the specified file a directory?
994 public int
995 is_dir(filename)
996 char *filename;
998 int isdir = 0;
1000 #if HAVE_STAT
1002 int r;
1003 struct stat statbuf;
1005 r = stat(filename, &statbuf);
1006 isdir = (r >= 0 && S_ISDIR(statbuf.st_mode));
1008 #else
1009 #ifdef _OSK
1011 int f;
1013 f = open(filename, S_IREAD | S_IFDIR);
1014 if (f >= 0)
1015 close(f);
1016 isdir = (f >= 0);
1018 #endif
1019 #endif
1020 return (isdir);
1024 * Returns NULL if the file can be opened and
1025 * is an ordinary file, otherwise an error message
1026 * (if it cannot be opened or is a directory, etc.)
1028 public char *
1029 bad_file(filename)
1030 char *filename;
1032 char *m = NULL;
1034 if (!force_open && is_dir(filename))
1036 static char is_a_dir[] = " is a directory";
1038 m = (char *) ecalloc(strlen(filename) + sizeof(is_a_dir),
1039 sizeof(char));
1040 strcpy(m, filename);
1041 strcat(m, is_a_dir);
1042 } else
1044 #if HAVE_STAT
1045 int r;
1046 struct stat statbuf;
1048 r = stat(filename, &statbuf);
1049 if (r < 0)
1051 m = errno_message(filename);
1052 } else if (force_open)
1054 m = NULL;
1055 } else if (!S_ISREG(statbuf.st_mode))
1057 static char not_reg[] = " is not a regular file (use -f to see it)";
1058 m = (char *) ecalloc(strlen(filename) + sizeof(not_reg),
1059 sizeof(char));
1060 strcpy(m, filename);
1061 strcat(m, not_reg);
1063 #endif
1065 return (m);
1069 * Return the size of a file, as cheaply as possible.
1070 * In Unix, we can stat the file.
1072 public POSITION
1073 filesize(f)
1074 int f;
1076 #if HAVE_STAT
1077 struct stat statbuf;
1079 if (fstat(f, &statbuf) >= 0)
1080 return ((POSITION) statbuf.st_size);
1081 #else
1082 #ifdef _OSK
1083 long size;
1085 if ((size = (long) _gs_size(f)) >= 0)
1086 return ((POSITION) size);
1087 #endif
1088 #endif
1089 return (seek_filesize(f));
1095 public char *
1096 shell_coption(VOID_PARAM)
1098 return ("-c");
1102 * Return last component of a pathname.
1104 public char *
1105 last_component(name)
1106 char *name;
1108 char *slash;
1110 for (slash = name + strlen(name); slash > name; )
1112 --slash;
1113 if (*slash == *PATHNAME_SEP || *slash == '/')
1114 return (slash + 1);
1116 return (name);