~ubuntu-branches/ubuntu/precise/util-linux/precise-proposed

« back to all changes in this revision

Viewing changes to misc-utils/look.c

  • Committer: Bazaar Package Importer
  • Author(s): Steve Langasek
  • Date: 2011-06-20 22:31:50 UTC
  • mfrom: (1.6.3 upstream) (4.5.1 sid)
  • Revision ID: james.westby@ubuntu.com-20110620223150-lz8wrv0946ihcz3z
Tags: 2.19.1-2ubuntu1
* Merge from Debian unstable, remaining changes:
  - Build for multiarch.
  - Add pre-depends on multiarch-support.
  - configure.ac: don't try to be clever about extracting a path name from
    $libdir to append to /usr in a way that's not overridable; instead,
    reuse the built-in configurable libexecdir.
  - Fix up the .pc.in files to know about libexecdir, so our substitutions
    don't leave us with unusable pkg-config files.
  - Install custom blkid.conf to use /dev/.blkid.tab since we don't
    expect device names to survive a reboot
  - Mention mountall(8) in fstab(5) manpages, along with its special
    options.
  - Since upstart is required in Ubuntu, the hwclock.sh init script is not
    called on startup and the hwclockfirst.sh init script is removed.
  - Drop depends on initscripts for the above.
  - Replace hwclock udev rule with an Upstart job.
  - For the case where mount is called with a directory to mount, look
    that directory up in mountall's /lib/init/fstab if we couldn't find
    it mentioned anywhere else.  This means "mount /proc", "mount /sys",
    etc. work.
  - mount.8 points to the cifs-utils package, not the obsolete smbfs one. 
* Dropped changes:
  - mount.preinst: lsb_release has been fixed in lucid and above to be
    usable without configuration, so we don't have to diverge from Debian
    here anymore.
* Changes merged upstream:
  - sfdisk support for '+' with '-N'
  - mount/umount.c: fix a segfault on umount with empty mtab entry
  - Fix arbitrary unmount with fuse security issue

Show diffs side-by-side

added added

removed removed

Lines of Context:
59
59
#include <strings.h>
60
60
#include <ctype.h>
61
61
#include <getopt.h>
 
62
 
 
63
#include "nls.h"
 
64
#include "xalloc.h"
62
65
#include "pathnames.h"
63
 
#include "nls.h"
64
66
 
65
67
#define EQUAL           0
66
68
#define GREATER         1
75
77
 
76
78
static char *binary_search (char *, char *);
77
79
static int compare (char *, char *);
78
 
static void err (const char *fmt, ...);
79
80
static char *linear_search (char *, char *);
80
81
static int look (char *, char *);
81
82
static void print_from (char *, char *);
101
102
        while ((ch = getopt(argc, argv, "adft:")) != -1)
102
103
                switch(ch) {
103
104
                case 'a':
104
 
                        file = _PATH_WORDS_ALT;
 
105
                        file = _PATH_WORDS_ALT;
105
106
                        break;
106
107
                case 'd':
107
108
                        dflag = 1;
136
137
                *++p = '\0';
137
138
 
138
139
        if ((fd = open(file, O_RDONLY, 0)) < 0 || fstat(fd, &sb))
139
 
                err("%s: %s", file, strerror(errno));
 
140
                err(EXIT_FAILURE, "%s", file);
140
141
        front = mmap(NULL, (size_t) sb.st_size, PROT_READ,
141
142
#ifdef MAP_FILE
142
143
                     MAP_FILE |
144
145
                     MAP_SHARED, fd, (off_t) 0);
145
146
        if
146
147
#ifdef MAP_FAILED
147
 
           (front == MAP_FAILED)
 
148
                (front == MAP_FAILED)
148
149
#else
149
 
           ((void *)(front) <= (void *)0)
 
150
                ((void *)(front) <= (void *)0)
150
151
#endif
151
 
                err("%s: %s", file, strerror(errno));
 
152
                        err(EXIT_FAILURE, "%s", file);
152
153
 
153
154
#if 0
154
155
        /* workaround for mmap problem (rmiller@duskglow.com) */
177
178
        } else
178
179
                stringlen = strlen(string);
179
180
 
180
 
        comparbuf = malloc(stringlen+1);
181
 
        if (comparbuf == NULL)
182
 
                err(_("Out of memory"));
 
181
        comparbuf = xmalloc(stringlen+1);
183
182
 
184
183
        front = binary_search(front, back);
185
184
        front = linear_search(front, back);
186
185
 
187
186
        if (front)
188
187
                print_from(front, back);
 
188
 
 
189
        free(comparbuf);
 
190
 
189
191
        return (front ? 0 : 1);
190
192
}
191
193
 
293
295
                        eol = 0;
294
296
                        while (front < back && !eol) {
295
297
                                if (putchar(*front) == EOF)
296
 
                                        err("stdout: %s", strerror(errno));
 
298
                                        err(EXIT_FAILURE, "stdout");
297
299
                                if (*front++ == '\n')
298
300
                                        eol = 1;
299
301
                        }
351
353
        (void)fprintf(stderr, _("usage: look [-dfa] [-t char] string [file]\n"));
352
354
        exit(2);
353
355
}
354
 
 
355
 
#if __STDC__
356
 
#include <stdarg.h>
357
 
#else
358
 
#include <varargs.h>
359
 
#endif
360
 
 
361
 
void
362
 
#if __STDC__
363
 
err(const char *fmt, ...)
364
 
#else
365
 
err(fmt, va_alist)
366
 
        char *fmt;
367
 
        va_dcl
368
 
#endif
369
 
{
370
 
        va_list ap;
371
 
#if __STDC__
372
 
        va_start(ap, fmt);
373
 
#else
374
 
        va_start(ap);
375
 
#endif
376
 
        (void)fprintf(stderr, "look: ");
377
 
        (void)vfprintf(stderr, fmt, ap);
378
 
        va_end(ap);
379
 
        (void)fprintf(stderr, "\n");
380
 
        exit(2);
381
 
        /* NOTREACHED */
382
 
}