File indexing completed on 2025-05-11 08:24:19
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035 #ifdef HAVE_CONFIG_H
0036 #include "config.h"
0037 #endif
0038
0039 #if 0
0040 #include <sys/cdefs.h>
0041 #ifndef lint
0042 #if 0
0043 static char sccsid[] = "@(#)util.c 8.5 (Berkeley) 4/28/95";
0044 #else
0045 __RCSID("$NetBSD: util.c,v 1.28 2005/06/17 14:36:16 hira Exp $");
0046 #endif
0047 #endif
0048 #endif
0049
0050 #include <sys/types.h>
0051 #include <sys/stat.h>
0052
0053 #include <ctype.h>
0054 #include "err.h"
0055 #include "fts.h"
0056 #include <limits.h>
0057 #include <stdio.h>
0058 #include <stdlib.h>
0059 #include <string.h>
0060 #include "vis.h"
0061
0062 #include "extern-ls.h"
0063
0064 #define SIZE_T_MAX 255
0065
0066 int
0067 safe_print(rtems_shell_ls_globals* globals, const char *src)
0068 {
0069 size_t len;
0070 char *name;
0071 int flags;
0072
0073 flags = VIS_NL | VIS_OCTAL;
0074 if (f_octal_escape)
0075 flags |= VIS_CSTYLE;
0076
0077 len = strlen(src);
0078 if (len != 0 && SIZE_T_MAX/len <= 4) {
0079 errx(exit_jump, EXIT_FAILURE, "%s: name too long", src);
0080
0081 }
0082
0083 name = (char *)malloc(4*len+1);
0084 if (name != NULL) {
0085 len = strvis(name, src, flags);
0086 printf("%s", name);
0087 free(name);
0088 return len;
0089 } else
0090 errx(exit_jump, EXIT_FAILURE, "out of memory!");
0091
0092 }
0093
0094 int
0095 printescaped(rtems_shell_ls_globals* globals RTEMS_UNUSED, const char *src)
0096 {
0097 unsigned char c;
0098 int n;
0099
0100 for (n = 0; (c = *src) != '\0'; ++src, ++n)
0101 if (isprint(c))
0102 (void)putchar(c);
0103 else
0104 (void)putchar('?');
0105 return n;
0106 }
0107
0108 void
0109 usage(rtems_shell_ls_globals* globals)
0110 {
0111
0112 (void)fprintf(stderr,
0113 "usage: %s [-AaBbCcdFfghikLlmnopqRrSsTtuWwx1] [file ...]\n",
0114 "ls");
0115 exit(EXIT_FAILURE);
0116
0117 }