Use err(3). Typo fix in usage string.

This commit is contained in:
Philippe Charnier 1997-06-23 06:47:12 +00:00
parent 0676cb8945
commit 4f971ac410
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=26837

View File

@ -25,7 +25,7 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* $Id: brandelf.c,v 1.5 1997/03/29 04:28:17 imp Exp $
* $Id: brandelf.c,v 1.6 1997/05/21 23:07:17 jdp Exp $
*/
#include <elf.h>
@ -34,8 +34,9 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <err.h>
int usage(void);
static void usage __P((void));
int
main(int argc, char **argv)
@ -59,30 +60,27 @@ main(int argc, char **argv)
}
argc -= optind;
argv += optind;
if (!argc) {
fprintf(stderr, "No file(s) specified.\n");
exit(1);
}
if (!argc)
errx(1, "no file(s) specified");
while (argc) {
int fd;
char buffer[EI_NIDENT];
char string[(EI_NIDENT-EI_BRAND)+1];
if ((fd = open(argv[0], O_RDWR, 0)) < 0) {
fprintf(stderr, "No such file %s.\n", argv[0]);
warnx("no such file %s", argv[0]);
retval = 1;
goto fail;
}
if (read(fd, buffer, EI_NIDENT) < EI_NIDENT) {
fprintf(stderr, "File '%s' too short.\n", argv[0]);
warnx("file '%s' too short", argv[0]);
retval = 1;
goto fail;
}
if (buffer[0] != ELFMAG0 || buffer[1] != ELFMAG1 ||
buffer[2] != ELFMAG2 || buffer[3] != ELFMAG3) {
fprintf(stderr, "File '%s' is not ELF format.\n",
argv[0]);
warnx("file '%s' is not ELF format", argv[0]);
retval = 1;
goto fail;
}
@ -101,8 +99,8 @@ main(int argc, char **argv)
strncpy(&buffer[EI_BRAND], type, EI_NIDENT-EI_BRAND);
lseek(fd, 0, SEEK_SET);
if (write(fd, buffer, EI_NIDENT) != EI_NIDENT) {
fprintf(stderr, "Error writing %s\n", argv[0]);
retval = 1;
warnx("error writing %s", argv[0]);
retval = 1;
goto fail;
}
}
@ -114,9 +112,9 @@ fail:
return retval;
}
int
usage(void)
static void
usage()
{
fprintf(stderr, "Usage: brandelf [-t string] file ...\n");
fprintf(stderr, "usage: brandelf [-t string] file ...\n");
exit(1);
}