split.c (43625) | split.c (68887) |
---|---|
1/* 2 * Copyright (c) 1987, 1993, 1994 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 26 unchanged lines hidden (view full) --- 35static const char copyright[] = 36"@(#) Copyright (c) 1987, 1993, 1994\n\ 37 The Regents of the University of California. All rights reserved.\n"; 38#endif /* not lint */ 39 40#ifndef lint 41#if 0 42static char sccsid[] = "@(#)split.c 8.2 (Berkeley) 4/16/94"; | 1/* 2 * Copyright (c) 1987, 1993, 1994 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 26 unchanged lines hidden (view full) --- 35static const char copyright[] = 36"@(#) Copyright (c) 1987, 1993, 1994\n\ 37 The Regents of the University of California. All rights reserved.\n"; 38#endif /* not lint */ 39 40#ifndef lint 41#if 0 42static char sccsid[] = "@(#)split.c 8.2 (Berkeley) 4/16/94"; |
43#else 44static const char rcsid[] = 45 "$FreeBSD: head/usr.bin/split/split.c 68887 2000-11-19 01:44:20Z jwd $"; |
|
43#endif 44#endif /* not lint */ 45 46#include <sys/param.h> 47#include <sys/types.h> 48 49#include <ctype.h> 50#include <err.h> 51#include <fcntl.h> 52#include <stdio.h> 53#include <stdlib.h> 54#include <string.h> 55#include <unistd.h> 56#include <regex.h> 57#include <sysexits.h> 58 59#define DEFLINE 1000 /* Default num lines per file. */ 60 | 46#endif 47#endif /* not lint */ 48 49#include <sys/param.h> 50#include <sys/types.h> 51 52#include <ctype.h> 53#include <err.h> 54#include <fcntl.h> 55#include <stdio.h> 56#include <stdlib.h> 57#include <string.h> 58#include <unistd.h> 59#include <regex.h> 60#include <sysexits.h> 61 62#define DEFLINE 1000 /* Default num lines per file. */ 63 |
61long bytecnt; /* Byte count to split on. */ | 64size_t bytecnt; /* Byte count to split on. */ |
62long numlines; /* Line count to split on. */ 63int file_open; /* If a file open. */ 64int ifd = -1, ofd = -1; /* Input/output file descriptors. */ 65char bfr[MAXBSIZE]; /* I/O buffer. */ 66char fname[MAXPATHLEN]; /* File name prefix. */ 67regex_t rgx; 68int pflag; 69 --- 31 unchanged lines hidden (view full) --- 101 } 102 break; 103 case '-': /* Undocumented: historic stdin flag. */ 104 if (ifd != -1) 105 usage(); 106 ifd = 0; 107 break; 108 case 'b': /* Byte count. */ | 65long numlines; /* Line count to split on. */ 66int file_open; /* If a file open. */ 67int ifd = -1, ofd = -1; /* Input/output file descriptors. */ 68char bfr[MAXBSIZE]; /* I/O buffer. */ 69char fname[MAXPATHLEN]; /* File name prefix. */ 70regex_t rgx; 71int pflag; 72 --- 31 unchanged lines hidden (view full) --- 104 } 105 break; 106 case '-': /* Undocumented: historic stdin flag. */ 107 if (ifd != -1) 108 usage(); 109 ifd = 0; 110 break; 111 case 'b': /* Byte count. */ |
109 if ((bytecnt = strtol(optarg, &ep, 10)) <= 0 || | 112 if ((bytecnt = strtoq(optarg, &ep, 10)) <= 0 || |
110 (*ep != '\0' && *ep != 'k' && *ep != 'm')) 111 errx(EX_USAGE, 112 "%s: illegal byte count", optarg); 113 if (*ep == 'k') 114 bytecnt *= 1024; 115 else if (*ep == 'm') 116 bytecnt *= 1048576; 117 break; --- 49 unchanged lines hidden (view full) --- 167 168/* 169 * split1 -- 170 * Split the input by bytes. 171 */ 172void 173split1() 174{ | 113 (*ep != '\0' && *ep != 'k' && *ep != 'm')) 114 errx(EX_USAGE, 115 "%s: illegal byte count", optarg); 116 if (*ep == 'k') 117 bytecnt *= 1024; 118 else if (*ep == 'm') 119 bytecnt *= 1048576; 120 break; --- 49 unchanged lines hidden (view full) --- 170 171/* 172 * split1 -- 173 * Split the input by bytes. 174 */ 175void 176split1() 177{ |
175 long bcnt; 176 int dist, len; | 178 size_t bcnt, dist, len; |
177 char *C; 178 179 for (bcnt = 0;;) 180 switch ((len = read(ifd, bfr, MAXBSIZE))) { 181 case 0: 182 exit(0); 183 case -1: 184 err(EX_IOERR, "read"); --- 131 unchanged lines hidden --- | 179 char *C; 180 181 for (bcnt = 0;;) 182 switch ((len = read(ifd, bfr, MAXBSIZE))) { 183 case 0: 184 exit(0); 185 case -1: 186 err(EX_IOERR, "read"); --- 131 unchanged lines hidden --- |