parent
a58ad2bc31
commit
f7e4fac687
|
@ -1,36 +0,0 @@
|
||||||
cmake_minimum_required (VERSION 2.9)
|
|
||||||
project (ack-misc)
|
|
||||||
|
|
||||||
set(SRC_MODULES abmodules.c)
|
|
||||||
set(SRC_ELFLOD aelflod.c)
|
|
||||||
set(SRC_ANM anm.c)
|
|
||||||
set(SRC_ASHOW ashow.c)
|
|
||||||
set(SRC_ASIZE asize.c)
|
|
||||||
set(SRC_ASLOD aslod.c)
|
|
||||||
set(SRC_ASTRIP astrip.c)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
add_executable(anm ${SRC_ANM})
|
|
||||||
add_executable(ashow ${SRC_ASHOW})
|
|
||||||
add_executable(asize ${SRC_ASIZE})
|
|
||||||
add_executable(astrip ${SRC_ASTRIP})
|
|
||||||
add_executable(aslod ${SRC_ASLOD})
|
|
||||||
|
|
||||||
|
|
||||||
include_directories(${INCLUDE_DIRS})
|
|
||||||
|
|
||||||
# Set linking options
|
|
||||||
#target_link_libraries(ack-modules emheaders object)
|
|
||||||
target_link_libraries(anm emheaders object)
|
|
||||||
target_link_libraries(ashow emheaders object)
|
|
||||||
target_link_libraries(asize emheaders object)
|
|
||||||
target_link_libraries(astrip emheaders object system)
|
|
||||||
target_link_libraries(aslod emheaders object)
|
|
||||||
|
|
||||||
install(TARGETS anm DESTINATION bin)
|
|
||||||
install(TARGETS ashow DESTINATION bin)
|
|
||||||
install(TARGETS asize DESTINATION bin)
|
|
||||||
install(TARGETS astrip DESTINATION bin)
|
|
||||||
install(TARGETS aslod DESTINATION bin)
|
|
|
@ -32,18 +32,22 @@ long s_base[S_MAX]; /* for specially encoded bases */
|
||||||
char *filename;
|
char *filename;
|
||||||
int narg;
|
int narg;
|
||||||
|
|
||||||
|
extern int rd_unsigned2();
|
||||||
|
|
||||||
static const char prefix[] = "_bmodule_";
|
static const char prefix[] = "_bmodule_";
|
||||||
|
|
||||||
static struct stringlist modules;
|
static struct stringlist modules;
|
||||||
|
|
||||||
static void do_file(FILE *fd)
|
static void do_file(int fd)
|
||||||
{
|
{
|
||||||
struct outhead hbuf;
|
struct outhead hbuf;
|
||||||
|
struct outname *nbufp = NULL;
|
||||||
char *cbufp;
|
char *cbufp;
|
||||||
long fi_to_co;
|
long fi_to_co;
|
||||||
long n;
|
long n;
|
||||||
unsigned readcount;
|
unsigned readcount;
|
||||||
|
int i,j;
|
||||||
|
int compare();
|
||||||
|
|
||||||
read_error = 0;
|
read_error = 0;
|
||||||
rd_fdopen(fd);
|
rd_fdopen(fd);
|
||||||
|
@ -71,6 +75,7 @@ static void do_file(FILE *fd)
|
||||||
while (--n >= 0)
|
while (--n >= 0)
|
||||||
{
|
{
|
||||||
struct outname nbuf;
|
struct outname nbuf;
|
||||||
|
struct stringfragment* f;
|
||||||
|
|
||||||
rd_name(&nbuf, 1);
|
rd_name(&nbuf, 1);
|
||||||
if (read_error)
|
if (read_error)
|
||||||
|
@ -102,12 +107,12 @@ corrupt:
|
||||||
fatal("%s --- corrupt", filename);
|
fatal("%s --- corrupt", filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void process(FILE* fd)
|
static void process(int fd)
|
||||||
{
|
{
|
||||||
uint16_t magic = rd_unsigned2(fd);
|
uint16_t magic = rd_unsigned2(fd);
|
||||||
switch(magic) {
|
switch(magic) {
|
||||||
case O_MAGIC:
|
case O_MAGIC:
|
||||||
fseek(fd, 0L, SEEK_SET);
|
lseek(fd, 0L, 0);
|
||||||
do_file(fd);
|
do_file(fd);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -119,7 +124,7 @@ static void process(FILE* fd)
|
||||||
|
|
||||||
while (rd_arhdr(fd, &archive_header))
|
while (rd_arhdr(fd, &archive_header))
|
||||||
{
|
{
|
||||||
long nextpos = ftell(fd) + archive_header.ar_size;
|
long nextpos = lseek(fd, 0L, SEEK_CUR) + archive_header.ar_size;
|
||||||
if (nextpos & 1)
|
if (nextpos & 1)
|
||||||
nextpos++;
|
nextpos++;
|
||||||
|
|
||||||
|
@ -127,7 +132,7 @@ static void process(FILE* fd)
|
||||||
filename = buf;
|
filename = buf;
|
||||||
if (strcmp(filename, SYMDEF) != 0)
|
if (strcmp(filename, SYMDEF) != 0)
|
||||||
do_file(fd);
|
do_file(fd);
|
||||||
fseek(fd, nextpos, SEEK_SET);
|
lseek(fd, nextpos, 0);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -139,6 +144,7 @@ static void process(FILE* fd)
|
||||||
|
|
||||||
int main(int argc, char* const argv[])
|
int main(int argc, char* const argv[])
|
||||||
{
|
{
|
||||||
|
int opt;
|
||||||
FILE* outputfp = NULL;
|
FILE* outputfp = NULL;
|
||||||
|
|
||||||
program_name = argv[0];
|
program_name = argv[0];
|
||||||
|
@ -163,15 +169,15 @@ int main(int argc, char* const argv[])
|
||||||
|
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
FILE *fd;
|
int fd;
|
||||||
|
|
||||||
filename = argv[optind++];
|
filename = argv[optind++];
|
||||||
if (!filename)
|
if (!filename)
|
||||||
break;
|
break;
|
||||||
if ((fd = fopen(filename, "rb")) == NULL)
|
if ((fd = open(filename, 0)) < 0)
|
||||||
fatal("cannot open %s: %s", filename, strerror(errno));
|
fatal("cannot open %s: %s", filename, strerror(errno));
|
||||||
process(fd);
|
process(fd);
|
||||||
fclose(fd);
|
close(fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (outputfp)
|
if (outputfp)
|
||||||
|
|
|
@ -25,7 +25,6 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <sys/stat.h>
|
|
||||||
#include "out.h"
|
#include "out.h"
|
||||||
|
|
||||||
#define ASSERT(x) switch (2) { case 0: case (x): ; }
|
#define ASSERT(x) switch (2) { case 0: case (x): ; }
|
||||||
|
@ -860,12 +859,7 @@ int main(int argc, char* argv[])
|
||||||
if (ferror(output))
|
if (ferror(output))
|
||||||
fatal("output write error");
|
fatal("output write error");
|
||||||
if (outputfile)
|
if (outputfile)
|
||||||
{
|
chmod(outputfile, 0755);
|
||||||
/* mode = 0755 in standard UNIX */
|
|
||||||
chmod(outputfile, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Summarise what we've done. */
|
/* Summarise what we've done. */
|
||||||
|
|
||||||
|
|
|
@ -10,10 +10,12 @@
|
||||||
** anm [-gopruns] [name ...]
|
** anm [-gopruns] [name ...]
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <fcntl.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "object.h"
|
#include "object.h"
|
||||||
#include "out.h"
|
#include "out.h"
|
||||||
|
@ -36,10 +38,10 @@ long s_base[S_MAX]; /* for specially encoded bases */
|
||||||
char *filename;
|
char *filename;
|
||||||
int narg;
|
int narg;
|
||||||
|
|
||||||
static void process(FILE *);
|
void do_file();
|
||||||
static void do_file(FILE *);
|
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
main(argc, argv)
|
||||||
|
char **argv;
|
||||||
{
|
{
|
||||||
|
|
||||||
if (--argc>0 && argv[1][0]=='-' && argv[1][1]!=0) {
|
if (--argc>0 && argv[1][0]=='-' && argv[1][1]!=0) {
|
||||||
|
@ -86,21 +88,23 @@ int main(int argc, char **argv)
|
||||||
narg = argc;
|
narg = argc;
|
||||||
|
|
||||||
while(argc--) {
|
while(argc--) {
|
||||||
FILE *fd;
|
int fd;
|
||||||
|
|
||||||
filename = *++argv;
|
filename = *++argv;
|
||||||
if ((fd = fopen(filename, "rb")) == NULL) {
|
if ((fd = open(filename, 0)) < 0) {
|
||||||
fprintf(stderr, "anm: cannot open %s\n", filename);
|
fprintf(stderr, "anm: cannot open %s\n", filename);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
process(fd);
|
process(fd);
|
||||||
fclose(fd);
|
close(fd);
|
||||||
}
|
}
|
||||||
exit(EXIT_SUCCESS);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extern int rd_unsigned2();
|
||||||
|
|
||||||
static void process(FILE *fd)
|
process(fd)
|
||||||
|
int fd;
|
||||||
{
|
{
|
||||||
unsigned int magic;
|
unsigned int magic;
|
||||||
long nextpos;
|
long nextpos;
|
||||||
|
@ -112,13 +116,13 @@ static void process(FILE *fd)
|
||||||
magic = rd_unsigned2(fd);
|
magic = rd_unsigned2(fd);
|
||||||
switch(magic) {
|
switch(magic) {
|
||||||
case O_MAGIC:
|
case O_MAGIC:
|
||||||
fseek(fd, 0L, SEEK_SET);
|
lseek(fd, 0L, 0);
|
||||||
do_file(fd);
|
do_file(fd);
|
||||||
break;
|
break;
|
||||||
case ARMAG:
|
case ARMAG:
|
||||||
case AALMAG:
|
case AALMAG:
|
||||||
while (rd_arhdr(fd, &archive_header)) {
|
while (rd_arhdr(fd, &archive_header)) {
|
||||||
nextpos = ftell(fd) + archive_header.ar_size;
|
nextpos = lseek(fd, 0L, 1) + archive_header.ar_size;
|
||||||
if (nextpos & 1) nextpos++;
|
if (nextpos & 1) nextpos++;
|
||||||
strncpy(buf,archive_header.ar_name,sizeof(archive_header.ar_name));
|
strncpy(buf,archive_header.ar_name,sizeof(archive_header.ar_name));
|
||||||
filename = buf;
|
filename = buf;
|
||||||
|
@ -126,7 +130,7 @@ static void process(FILE *fd)
|
||||||
printf("\n%s:\n", filename);
|
printf("\n%s:\n", filename);
|
||||||
do_file(fd);
|
do_file(fd);
|
||||||
}
|
}
|
||||||
fseek(fd, nextpos, SEEK_SET);
|
lseek(fd, nextpos, 0);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -135,7 +139,9 @@ static void process(FILE *fd)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void do_file(FILE *fd)
|
void
|
||||||
|
do_file(fd)
|
||||||
|
int fd;
|
||||||
{
|
{
|
||||||
struct outname *nbufp = NULL;
|
struct outname *nbufp = NULL;
|
||||||
struct outname nbuf;
|
struct outname nbuf;
|
||||||
|
@ -295,7 +301,8 @@ static void do_file(FILE *fd)
|
||||||
free((char *)cbufp);
|
free((char *)cbufp);
|
||||||
}
|
}
|
||||||
|
|
||||||
int compare(struct outname *p1, struct outname *p2)
|
compare(p1, p2)
|
||||||
|
struct outname *p1, *p2;
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
|
@ -329,7 +336,7 @@ int compare(struct outname *p1, struct outname *p2)
|
||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void rd_fatal(void)
|
rd_fatal()
|
||||||
{
|
{
|
||||||
fprintf(stderr,"read error on %s\n", filename);
|
fprintf(stderr,"read error on %s\n", filename);
|
||||||
read_error = 1;
|
read_error = 1;
|
||||||
|
|
|
@ -5,25 +5,18 @@ static char rcsid[] = "$Id$";
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdarg.h>
|
#include <sys/types.h>
|
||||||
#include "object.h"
|
#include <sys/stat.h>
|
||||||
#include "out.h"
|
#include <object.h>
|
||||||
|
#include <out.h>
|
||||||
|
|
||||||
#define OK 0 /* Return value of gethead if Orl Korekt. */
|
#define OK 0 /* Return value of gethead if Orl Korekt. */
|
||||||
#define BMASK 0xFF /* To extract least significant 8 bits from an int. */
|
#define BMASK 0xFF /* To extract least significant 8 bits from an int. */
|
||||||
|
|
||||||
/* Forward declarations */
|
|
||||||
static void show(register struct outhead *);
|
|
||||||
static void showflags(unsigned int);
|
|
||||||
static void showsect(void);
|
|
||||||
static void showrelo(void);
|
|
||||||
static void showname(struct outname *);
|
|
||||||
static char *myalloc(unsigned int);
|
|
||||||
static void error(char *, ...);
|
|
||||||
|
|
||||||
|
|
||||||
/* ARGSUSED */
|
/* ARGSUSED */
|
||||||
int main(int argc, char **argv)
|
main(argc, argv)
|
||||||
|
int argc;
|
||||||
|
char *argv[];
|
||||||
# define prog argv[0]
|
# define prog argv[0]
|
||||||
{
|
{
|
||||||
register char **arg = argv;
|
register char **arg = argv;
|
||||||
|
@ -43,7 +36,6 @@ int main(int argc, char **argv)
|
||||||
}
|
}
|
||||||
rd_close();
|
rd_close();
|
||||||
}
|
}
|
||||||
return EXIT_SUCCESS;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -51,12 +43,14 @@ int main(int argc, char **argv)
|
||||||
* NB. The header has already been read and is in the struct outhead `headp'
|
* NB. The header has already been read and is in the struct outhead `headp'
|
||||||
* points to.
|
* points to.
|
||||||
*/
|
*/
|
||||||
static void show(register struct outhead *headp)
|
show(headp)
|
||||||
|
register struct outhead *headp;
|
||||||
{
|
{
|
||||||
register int i;
|
register int i;
|
||||||
register struct outname *np;
|
register struct outname *np;
|
||||||
register struct outname *name; /* Dynamically allocated name-array. */
|
register struct outname *name; /* Dynamically allocated name-array. */
|
||||||
register char *string;/* Base of string area. */
|
register char *string;/* Base of string area. */
|
||||||
|
extern char *myalloc();
|
||||||
|
|
||||||
printf("Version %d\n", headp->oh_stamp);
|
printf("Version %d\n", headp->oh_stamp);
|
||||||
showflags((unsigned) headp->oh_flags);
|
showflags((unsigned) headp->oh_flags);
|
||||||
|
@ -96,12 +90,8 @@ static void show(register struct outhead *headp)
|
||||||
/*
|
/*
|
||||||
* Now we can show all names.
|
* Now we can show all names.
|
||||||
*/
|
*/
|
||||||
for (np = &name[0]; np < &name[headp->oh_nname]; np++)
|
for (np = &name[0]; np < &name[headp->oh_nname]; np++) {
|
||||||
{
|
printf("Name %d:\n", np - name);
|
||||||
/* In C99 this should be "%td" but we are in ANSI C89,
|
|
||||||
* so we typecast explicitly to int here.
|
|
||||||
*/
|
|
||||||
printf("Name %d:\n", (int)(np - name));
|
|
||||||
showname(np);
|
showname(np);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -109,7 +99,8 @@ static void show(register struct outhead *headp)
|
||||||
/*
|
/*
|
||||||
* Show flags from header.
|
* Show flags from header.
|
||||||
*/
|
*/
|
||||||
static void showflags(unsigned int flagword)
|
showflags(flagword)
|
||||||
|
unsigned flagword;
|
||||||
{
|
{
|
||||||
if (flagword & HF_LINK) printf("unresolved references left\n");
|
if (flagword & HF_LINK) printf("unresolved references left\n");
|
||||||
}
|
}
|
||||||
|
@ -117,7 +108,7 @@ static void showflags(unsigned int flagword)
|
||||||
/*
|
/*
|
||||||
* Show a section.
|
* Show a section.
|
||||||
*/
|
*/
|
||||||
static void showsect(void)
|
showsect()
|
||||||
{
|
{
|
||||||
struct outsect section;
|
struct outsect section;
|
||||||
|
|
||||||
|
@ -132,7 +123,7 @@ static void showsect(void)
|
||||||
/*
|
/*
|
||||||
* Show a relocation record.
|
* Show a relocation record.
|
||||||
*/
|
*/
|
||||||
static void showrelo(void)
|
showrelo()
|
||||||
{
|
{
|
||||||
struct outrelo relrec;
|
struct outrelo relrec;
|
||||||
|
|
||||||
|
@ -180,7 +171,8 @@ static void showrelo(void)
|
||||||
/*
|
/*
|
||||||
* Show the name in the struct `namep' points to.
|
* Show the name in the struct `namep' points to.
|
||||||
*/
|
*/
|
||||||
static void showname(struct outname *namep)
|
showname(namep)
|
||||||
|
struct outname *namep;
|
||||||
{
|
{
|
||||||
if (namep->on_mptr)
|
if (namep->on_mptr)
|
||||||
printf("\t%s\n", namep->on_mptr);
|
printf("\t%s\n", namep->on_mptr);
|
||||||
|
@ -227,29 +219,29 @@ static void showname(struct outname *namep)
|
||||||
/*
|
/*
|
||||||
* Core allocation via malloc() but fatal if no core.
|
* Core allocation via malloc() but fatal if no core.
|
||||||
*/
|
*/
|
||||||
static char *myalloc(unsigned int u)
|
char *
|
||||||
|
myalloc(u)
|
||||||
|
unsigned int u;
|
||||||
{
|
{
|
||||||
register char *rcp;
|
register char *rcp;
|
||||||
|
|
||||||
rcp = malloc(u);
|
rcp = malloc(u);
|
||||||
if (rcp == (char *) NULL) {
|
if (rcp == (char *) 0) {
|
||||||
error("Out of core\n");
|
error("Out of core\n");
|
||||||
exit(EXIT_FAILURE);
|
exit(1);
|
||||||
}
|
}
|
||||||
return rcp;
|
return rcp;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void error(char *fmt, ...)
|
/* VARARGS1 */
|
||||||
|
error(s, a1, a2, a3, a4)
|
||||||
|
char *s;
|
||||||
{
|
{
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
/* Diagnostic print, no auto NL */
|
fprintf(stderr, s, a1, a2, a3, a4);
|
||||||
va_list ap;
|
|
||||||
va_start(ap, fmt);
|
|
||||||
vfprintf(stderr, fmt, ap);
|
|
||||||
va_end(ap);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void rd_fatal(void)
|
rd_fatal()
|
||||||
{
|
{
|
||||||
error("Error in reading the object file\n");
|
error("Error in reading the object file\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
|
|
|
@ -14,7 +14,8 @@
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
main(argc, argv)
|
||||||
|
char **argv;
|
||||||
{
|
{
|
||||||
struct outhead buf;
|
struct outhead buf;
|
||||||
struct outsect sbuf;
|
struct outsect sbuf;
|
||||||
|
@ -59,10 +60,10 @@ int main(int argc, char **argv)
|
||||||
printf(" = %ld = 0x%lx\n", sum, sum);
|
printf(" = %ld = 0x%lx\n", sum, sum);
|
||||||
rd_close();
|
rd_close();
|
||||||
}
|
}
|
||||||
exit(EXIT_SUCCESS);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void rd_fatal(void)
|
rd_fatal()
|
||||||
{
|
{
|
||||||
fprintf(stderr, "read error\n");
|
fprintf(stderr, "read error\n");
|
||||||
exit(2);
|
exit(2);
|
||||||
|
|
|
@ -287,10 +287,8 @@ int main(int argc, char* argv[])
|
||||||
if (ferror(output))
|
if (ferror(output))
|
||||||
fatal("output write error");
|
fatal("output write error");
|
||||||
if (outputfile)
|
if (outputfile)
|
||||||
{
|
chmod(outputfile, 0755);
|
||||||
/* mode = 0755 in standard UNIX */
|
|
||||||
chmod(outputfile, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
|
|
||||||
}
|
|
||||||
/* Summarise what we've done. */
|
/* Summarise what we've done. */
|
||||||
|
|
||||||
if (verbose)
|
if (verbose)
|
||||||
|
|
|
@ -4,11 +4,11 @@
|
||||||
*/
|
*/
|
||||||
/* $Id$ */
|
/* $Id$ */
|
||||||
|
|
||||||
|
#include <fcntl.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <sys/stat.h>
|
#include <unistd.h>
|
||||||
#include "system.h"
|
|
||||||
#include "object.h"
|
#include "object.h"
|
||||||
#include "out.h"
|
#include "out.h"
|
||||||
|
|
||||||
|
@ -18,40 +18,34 @@
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
char tname[L_tmpnam];
|
char temp_name[] = "/tmp/sXXXXXX";
|
||||||
|
char *tname;
|
||||||
FILE *tf;
|
FILE *tf;
|
||||||
struct outhead buf;
|
struct outhead buf;
|
||||||
int readerror, writeerror;
|
int readerror, writeerror;
|
||||||
|
|
||||||
|
main(argc, argv)
|
||||||
static int copy(char *, char *, long, FILE *, FILE *);
|
char **argv;
|
||||||
static int strip(char *);
|
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
|
||||||
{
|
{
|
||||||
int status;
|
int status;
|
||||||
|
|
||||||
signal(SIGHUP, SIG_IGN);
|
signal(SIGHUP, SIG_IGN);
|
||||||
signal(SIGINT, SIG_IGN);
|
signal(SIGINT, SIG_IGN);
|
||||||
signal(SIGQUIT, SIG_IGN);
|
signal(SIGQUIT, SIG_IGN);
|
||||||
if (sys_tmpnam(tname)==NULL)
|
close(mkstemp(temp_name));
|
||||||
{
|
|
||||||
fprintf(stderr, "astrip: cannot create temporary filename\n");
|
|
||||||
return(1);
|
|
||||||
}
|
|
||||||
fclose(fopen(tname,"wb"));
|
|
||||||
while(--argc) {
|
while(--argc) {
|
||||||
if ((status = strip(argv[argc])) > 1)
|
if ((status = strip(argv[argc])) > 1)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
remove(tname);
|
unlink(temp_name);
|
||||||
return status;
|
exit(status);
|
||||||
}
|
}
|
||||||
|
|
||||||
int strip(char *name)
|
strip(name)
|
||||||
|
char *name;
|
||||||
{
|
{
|
||||||
long size;
|
long size;
|
||||||
FILE *fw;
|
int fw;
|
||||||
|
|
||||||
if (! rd_open(name)) {
|
if (! rd_open(name)) {
|
||||||
fprintf(stderr, "astrip: cannot open %s\n", name);
|
fprintf(stderr, "astrip: cannot open %s\n", name);
|
||||||
|
@ -84,46 +78,48 @@ int strip(char *name)
|
||||||
rd_close();
|
rd_close();
|
||||||
return(1);
|
return(1);
|
||||||
}
|
}
|
||||||
fw = fopen(tname, "ab");
|
fw = open(tname, 2);
|
||||||
if ((fw == NULL) || (fseek(fw, (long)SZ_HEAD, SEEK_SET)!=0)) {
|
if (fw < 0 || lseek(fw, (long)SZ_HEAD, 0) < 0) {
|
||||||
fprintf(stderr, "astrip: cannot create temp file %s\n", tname);
|
fprintf(stderr, "astrip: cannot create temp file %s\n", tname);
|
||||||
rd_close();
|
rd_close();
|
||||||
fclose(fw);
|
close(fw);
|
||||||
return(2);
|
return(2);
|
||||||
}
|
}
|
||||||
if(copy(name, tname, size, rd_fd(), fw)) {
|
if(copy(name, tname, size, rd_fd(), fw)) {
|
||||||
rd_close();
|
rd_close();
|
||||||
fclose(fw);
|
close(fw);
|
||||||
return(1);
|
return(1);
|
||||||
}
|
}
|
||||||
rd_close();
|
rd_close();
|
||||||
fclose(fw);
|
close(fw);
|
||||||
size += SZ_HEAD;
|
size += SZ_HEAD;
|
||||||
if (! rd_open(tname)) {
|
if (! rd_open(tname)) {
|
||||||
fprintf(stderr, "astrip: cannot read temp file %s\n", tname);
|
fprintf(stderr, "astrip: cannot read temp file %s\n", tname);
|
||||||
return(2);
|
return(2);
|
||||||
}
|
}
|
||||||
fw = fopen(name, "wb");
|
fw = creat(name, 0777);
|
||||||
if (fw == NULL) {
|
if (fw < 0) {
|
||||||
fprintf(stderr, "astrip: cannot write %s\n", name);
|
fprintf(stderr, "astrip: cannot write %s\n", name);
|
||||||
rd_close();
|
rd_close();
|
||||||
return(1);
|
return(1);
|
||||||
}
|
}
|
||||||
if(copy(tname, name, size, rd_fd(), fw)) {
|
if(copy(tname, name, size, rd_fd(), fw)) {
|
||||||
fclose(fw);
|
close(fw);
|
||||||
rd_close();
|
rd_close();
|
||||||
return(2);
|
return(2);
|
||||||
}
|
}
|
||||||
fclose(fw);
|
|
||||||
|
close(fw);
|
||||||
rd_close();
|
rd_close();
|
||||||
/* Change the mode to everything. */
|
|
||||||
chmod(name,S_IRWXU | S_IRWXG | S_IRWXO);
|
|
||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int copy(char *fnam, char *tnam, long size, FILE *fr, FILE *fw)
|
copy(fnam, tnam, size, fr, fw)
|
||||||
|
char *fnam;
|
||||||
|
char *tnam;
|
||||||
|
long size;
|
||||||
{
|
{
|
||||||
register int s;
|
register s, n;
|
||||||
char lbuf[512];
|
char lbuf[512];
|
||||||
|
|
||||||
while(size != (long)0) {
|
while(size != (long)0) {
|
||||||
|
@ -145,12 +141,12 @@ static int copy(char *fnam, char *tnam, long size, FILE *fr, FILE *fw)
|
||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void rd_fatal(void)
|
rd_fatal()
|
||||||
{
|
{
|
||||||
readerror = 1;
|
readerror = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wr_fatal(void)
|
wr_fatal()
|
||||||
{
|
{
|
||||||
writeerror = 1;
|
writeerror = 1;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue