/[gentoo-projects]/pax-utils/scanelf.c
Gentoo

Diff of /pax-utils/scanelf.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.3 Revision 1.4
1/* 1/*
2 * Copyright 2003 Ned Ludd <solar@gentoo.org> 2 * Copyright 2003 Ned Ludd <solar@gentoo.org>
3 * Copyright 1999-2003 Gentoo Technologies, Inc. 3 * Copyright 1999-2003 Gentoo Technologies, Inc.
4 * Distributed under the terms of the GNU General Public License v2 4 * Distributed under the terms of the GNU General Public License v2
5 * $Header: /var/cvsroot/gentoo-projects/pax-utils/scanelf.c,v 1.3 2003/10/26 23:42:10 solar Exp $ 5 * $Header: /var/cvsroot/gentoo-projects/pax-utils/scanelf.c,v 1.4 2003/11/01 08:58:23 solar Exp $
6 * 6 *
7 ******************************************************************** 7 ********************************************************************
8 * This program is free software; you can redistribute it and/or 8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as 9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of the 10 * published by the Free Software Foundation; either version 2 of the
30#include <dirent.h> 30#include <dirent.h>
31#include <getopt.h> 31#include <getopt.h>
32 32
33#include "paxelf.h" 33#include "paxelf.h"
34 34
35static const char *rcsid = "$Id: scanelf.c,v 1.3 2003/10/26 23:42:10 solar Exp $"; 35static const char *rcsid =
36 "$Id: scanelf.c,v 1.4 2003/11/01 08:58:23 solar Exp $";
36 37
37#define PARSE_FLAGS "hvlp" 38#define PARSE_FLAGS "hvlp"
38static struct option const long_options[] = { 39static struct option const long_options[] = {
39 {"help", no_argument, 0, 'h'}, 40 {"help", no_argument, 0, 'h'},
40 {"version", no_argument, 0, 'v'}, 41 {"version", no_argument, 0, 'v'},
48{ 49{
49 elfobj *elf = NULL; 50 elfobj *elf = NULL;
50 register DIR *dir; 51 register DIR *dir;
51 register struct dirent *dentry; 52 register struct dirent *dentry;
52 53
53 if (chdir(path) == 0) { 54 if ((chdir(path) == 0) && ((dir = opendir(path)))) {
54 if ((dir = opendir(path))) {
55 while ((dentry = readdir(dir))) { 55 while ((dentry = readdir(dir))) {
56 /* verify this is real ELF */ 56 /* verify this is real ELF */
57 if ((elf = readelf(dentry->d_name)) != NULL) { 57 if ((elf = readelf(dentry->d_name)) != NULL) {
58 if (!check_elf_header(elf->ehdr)) 58 if (!check_elf_header(elf->ehdr))
59 if (IS_ELF(elf)) 59 if (IS_ELF(elf))
60 printf("%s %s %s/%s\n", 60 printf("%s %s %s/%s\n",
61 pax_short_flags(PAX_FLAGS(elf)), 61 pax_short_flags(PAX_FLAGS(elf)),
62 get_elfetype(elf->ehdr->e_type), path, 62 get_elfetype(elf->ehdr->e_type), path,
63 dentry->d_name); 63 dentry->d_name);
64 if (elf != NULL) { 64 if (elf != NULL) {
65 munmap(elf->data, elf->len); 65 munmap(elf->data, elf->len);
66 free(elf); 66 free(elf);
67 elf = NULL; 67 elf = NULL;
68 }
69 } 68 }
70 } 69 }
71 closedir(dir);
72 } 70 }
71 closedir(dir);
73 } 72 }
74} 73}
75 74
76 75
77/* display usage and exit */ 76/* display usage and exit */
78int usage(char **argv) 77int usage(char **argv)
79{ 78{
80 fprintf(stderr, 79 fprintf(stderr,
81 "Usage: %s [options] dir1 dir2 dirN...\n", 80 "Usage: %s [options] dir1 dir2 dirN...\n",
82 (*argv != NULL) ? argv[0] : __FILE__ "\b\b"); 81 (*argv != NULL) ? argv[0] : __FILE__ "\b\b");
83 exit(EXIT_FAILURE); 82 exit(EXIT_FAILURE);
84} 83}
85 84
86 85
87void showopt(int c, char *data) 86void showopt(int c, char *data)
88{ 87{
89 int i; 88 int i;
90 for (i = 0; long_options[i].name; i++) 89 for (i = 0; long_options[i].name; i++)
91 if (long_options[i].val == c) 90 if (long_options[i].val == c)
92 fprintf(stderr, " -%c, --%s\t: %s\n", c, long_options[i].name, data); 91 fprintf(stderr, " -%c, --%s\t: %s\n", c, long_options[i].name,
92 data);
93} 93}
94 94
95/* parse command line arguments and preform needed actions */ 95/* parse command line arguments and preform needed actions */
96void parseargs(int argc, char **argv) 96void parseargs(int argc, char **argv)
97{ 97{
111 showopt('v', "Print version and exit."); 111 showopt('v', "Print version and exit.");
112 exit(EXIT_SUCCESS); 112 exit(EXIT_SUCCESS);
113 case 'v': 113 case 'v':
114 fprintf(stderr, "%s compiled %s\n", __FILE__, __DATE__); 114 fprintf(stderr, "%s compiled %s\n", __FILE__, __DATE__);
115 fprintf(stderr, 115 fprintf(stderr,
116 "%s written for Gentoo Linux <solar@gentoo.org>\n\t%s\n", 116 "%s written for Gentoo Linux <solar@gentoo.org>\n\t%s\n",
117 (*argv != NULL) ? argv[0] : __FILE__ "\b\b", rcsid); 117 (*argv != NULL) ? argv[0] : __FILE__ "\b\b", rcsid);
118 exit(EXIT_SUCCESS); 118 exit(EXIT_SUCCESS);
119 case 'l': 119 case 'l':
120 /* scan ld.so.conf for ldpath */ 120 /* scan ld.so.conf for ldpath */
121 if ((fp = fopen("/etc/ld.so.conf", "r")) != NULL) { 121 if ((fp = fopen("/etc/ld.so.conf", "r")) != NULL) {
122 path = malloc(_POSIX_PATH_MAX); 122 path = malloc(_POSIX_PATH_MAX);

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.4

  ViewVC Help
Powered by ViewVC 1.1.20