elks-enhanced
public
Read
Owner: themaster
Branch: master
Commits: 6893
Updated: 2026-04-19 00:15
Git CLI clone URL
git clone https://www.xt-emporium.com/git/elks-enhanced.git
Fullscreen desktop URL
Code
Commits
History
Branches
Bug Reports
Discussions
Compare
Settings
elks-enhanced
/
elkscmd
/
minix1
/
sum.c
File editor
/* sum - checksum a file Author: Martin C. Atkins */ /* * This program was written by: * Martin C. Atkins, * University of York, * Heslington, * York. Y01 5DD * England * and is released into the public domain, on the condition * that this comment is always included without alteration. */ #include <sys/types.h> #include <fcntl.h> #include <stdlib.h> #include <unistd.h> #include <string.h> #include <stdio.h> int rc = 0; char *defargv[] = {"-", 0}; static char buf[2048]; void error(char *s, char *f) { fprintf(stderr, "sum: "); fprintf(stderr, s); if (f) fprintf(stderr, f); fprintf(stderr, "\n"); } void sum(int fd, char *fname) { register int i, n; long size = 0; unsigned crc = 0; unsigned tmp; while ((n = read(fd, buf, sizeof(buf))) > 0) { for (i = 0; i < n; i++) { crc = (crc >> 1) + ((crc & 1) ? 0x8000 : 0); tmp = buf[i] & 0377; crc += tmp; crc &= 0xffff; } size++; } if (n < 0) { if (fname) error("read error on ", fname); else error("read error", (char *) 0); rc = 1; return; } printf("%05u %6ld", crc, size); if (fname) printf(" %s", fname); printf("\n"); } int main(int argc, char **argv) { register int fd; if (*++argv == 0) argv = defargv; for (; *argv; argv++) { if (argv[0][0] == '-' && argv[0][1] == '\0') fd = 0; else fd = open(*argv, O_RDONLY); if (fd == -1) { error("can't open ", *argv); rc = 1; continue; } sum(fd, (argc > 2) ? *argv : (char *) 0); if (fd != 0) close(fd); } return(rc); }
Commit message
This repository is read-only for this account.
Repository snapshot
Current branch
master
Visibility
public
Your access
Read
Remote
Configured
File activity
View file history