scc

simple C compiler
git clone git://git.2f30.org/scc
Log | Files | Refs | README | LICENSE

commit f162377b18b3dfc9a4522fe03230eb89b581d344
parent a1ac9ad6601ed315c1dd8ecaa323296d17f39a14
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Fri, 29 Sep 2017 16:23:18 +0100

[ar] Use main.c for tha file where main is written

This is the way how all the tools are written.

Diffstat:
Dar/ar.c | 67-------------------------------------------------------------------
Aar/main.c | 68++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 68 insertions(+), 67 deletions(-)

diff --git a/ar/ar.c b/ar/ar.c @@ -1,67 +0,0 @@ - -#include <errno.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -#include <stat.h> - -int -main(int argc, char *argv[]) -{ - int c; - size_t n; - FILE *fp, *arfile; - char *fname, *arname = "lib.a"; - struct stat st; - - if ((arfile = fopen(arname, "wb")) == NULL) { - perror("ar:error opening library file"); - exit(1); - } - - fputs("!<arch>\n", arfile); - while ((fname = *++argv) != NULL) { - if ((n = strlen(fname)) > 16) { - fprintf(stderr, "ar:too long file name '%s'\n", fname); - exit(3); - } - if (stat(fname, &st) < 0) { - fprintf(stderr, - "ar:error opening object file '%s':%s\n", - fname, strerror(errno)); - exit(2); - } - fprintf(arfile, - "%-16s%-12llu%-6u%-6u%-8o%-10llu`\n", - fname, - (unsigned long long) st.st_atime, - (int) st.st_uid, (int) st.st_gid, - (int) st.st_mode, - (unsigned long long) st.st_size); - if ((fp = fopen(fname, "rb")) == NULL) { - fprintf(stderr, - "ar: error opening file '%s':%s\n", - fname, strerror(errno)); - exit(3); - } - while ((c = getc(fp)) != EOF) - putc(c, arfile); - if (st.st_size & 1) - putc('\n', arfile); - if (fclose(fp)) { - fprintf(stderr, - "ar:error reading from input file '%s':%s\n", - fname, strerror(errno)); - exit(4); - } - } - - if (fclose(arfile)) { - fprintf(stderr, - "ar:error writing to output file '%s':%s\n", - arname, strerror(errno)); - } - - return 0; -} diff --git a/ar/main.c b/ar/main.c @@ -0,0 +1,68 @@ +static char sccsid[] = "@(#) ./ar/main.c"; + +#include <errno.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#include <stat.h> + +int +main(int argc, char *argv[]) +{ + int c; + size_t n; + FILE *fp, *arfile; + char *fname, *arname = "lib.a"; + struct stat st; + + if ((arfile = fopen(arname, "wb")) == NULL) { + perror("ar:error opening library file"); + exit(1); + } + + fputs("!<arch>\n", arfile); + while ((fname = *++argv) != NULL) { + if ((n = strlen(fname)) > 16) { + fprintf(stderr, "ar:too long file name '%s'\n", fname); + exit(3); + } + if (stat(fname, &st) < 0) { + fprintf(stderr, + "ar:error opening object file '%s':%s\n", + fname, strerror(errno)); + exit(2); + } + fprintf(arfile, + "%-16s%-12llu%-6u%-6u%-8o%-10llu`\n", + fname, + (unsigned long long) st.st_atime, + (int) st.st_uid, (int) st.st_gid, + (int) st.st_mode, + (unsigned long long) st.st_size); + if ((fp = fopen(fname, "rb")) == NULL) { + fprintf(stderr, + "ar: error opening file '%s':%s\n", + fname, strerror(errno)); + exit(3); + } + while ((c = getc(fp)) != EOF) + putc(c, arfile); + if (st.st_size & 1) + putc('\n', arfile); + if (fclose(fp)) { + fprintf(stderr, + "ar:error reading from input file '%s':%s\n", + fname, strerror(errno)); + exit(4); + } + } + + if (fclose(arfile)) { + fprintf(stderr, + "ar:error writing to output file '%s':%s\n", + arname, strerror(errno)); + } + + return 0; +}