lxsplit-0.2.4/0000775000076400007640000000000011071407762012315 5ustar ozzieozzielxsplit-0.2.4/mkuoff_t.c0000664000076400007640000000620010751021753014265 0ustar ozzieozzie/* * $Id: mkuoff_t.c,v 1.1 2008/02/02 08:03:55 sezero Exp $ * Generates uoff_t.h which defines the unsigned version of off_t * as uoff_t, defines SIZEOF_ macros for the types we use. * * Copyright (c) 2008 O. Sezer * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to: * * Free Software Foundation, Inc. * 51 Franklin St, Fifth Floor, * Boston, MA 02110-1301 USA */ #include #include #include #include #include int main (void) { FILE *f; int ret = 0; f = fopen ("uoff_t.h", "w"); if (f == NULL) { ret = 1; fprintf (stderr, "Error: cannot create uoff_t.h\n"); } else { fprintf (f, "/* Generated by mkuoff_t.c */\n\n"); fprintf (f, "#ifndef _UOFF_T_H\n"); fprintf (f, "#define _UOFF_T_H\n\n"); fprintf (f, "#ifndef SIZEOF_CHAR\n"); fprintf (f, "#define SIZEOF_CHAR %d\n", (int)sizeof(char)); fprintf (f, "#endif\n\n"); fprintf (f, "#ifndef SIZEOF_SHORT\n"); fprintf (f, "#define SIZEOF_SHORT %d\n", (int)sizeof(short)); fprintf (f, "#endif\n\n"); fprintf (f, "#ifndef SIZEOF_INT\n"); fprintf (f, "#define SIZEOF_INT %d\n", (int)sizeof(int)); fprintf (f, "#endif\n\n"); fprintf (f, "#ifndef SIZEOF_LONG\n"); fprintf (f, "#define SIZEOF_LONG %d\n", (int)sizeof(long)); fprintf (f, "#endif\n\n"); fprintf (f, "#ifndef SIZEOF_LONG_LONG\n"); fprintf (f, "#define SIZEOF_LONG_LONG %d\n", (int)sizeof(long long)); fprintf (f, "#endif\n\n"); fprintf (f, "#ifndef SIZEOF_VOID_P\n"); fprintf (f, "#define SIZEOF_VOID_P %d\n", (int)sizeof(void *)); fprintf (f, "#endif\n\n"); fprintf (f, "#ifndef SIZEOF_SIZE_T\n"); fprintf (f, "#define SIZEOF_SIZE_T %d\n", (int)sizeof(size_t)); fprintf (f, "#endif\n\n"); fprintf (f, "#ifndef SIZEOF_OFF_T\n"); fprintf (f, "#define SIZEOF_OFF_T %d\n", (int)sizeof(off_t)); fprintf (f, "#endif\n\n"); if (sizeof(off_t) == sizeof(uint32_t)) { fprintf (f, "#define SIZEOF_UOFF_T %d\n", (int)sizeof(uint32_t)); fprintf (f, "typedef uint32_t uoff_t;\n\n"); } else if (sizeof(off_t) == sizeof(uint64_t)) { fprintf (f, "#define SIZEOF_UOFF_T %d\n", (int)sizeof(uint64_t)); fprintf (f, "typedef uint64_t uoff_t;\n\n"); } else if (sizeof(off_t) == sizeof(uintmax_t)) { fprintf (f, "#define SIZEOF_UOFF_T %d\n", (int)sizeof(uintmax_t)); fprintf (f, "typedef uintmax_t uoff_t;\n\n"); } else { fprintf (f, "#error Cannot define uoff_t\n\n"); fprintf (stderr, "Error: cannot define uoff_t\n"); ret = 1; } fprintf (f, "#endif\t/* _UOFF_T_H */\n\n"); fclose (f); } exit (ret); } lxsplit-0.2.4/Makefile0000664000076400007640000000312211020203076013735 0ustar ozzieozzie# GNU Makefile for building lxsplit # $Id: Makefile,v 1.5 2008/05/31 08:03:10 sezero Exp $ # # FIXME: This makefile is NOT suitable for cross-compiling, # because we are generating uoff_t.h during compilation.. # ####### Compiler, tools and options CC ?= gcc ifeq ($(CC),) CC := gcc endif INCPATH := . CFLAGS ?= -O2 CFLAGS := $(CFLAGS) -Wall -W -DNO_DEBUG LDLIBS := LDFLAGS := # 64 bit file offsets even on 32 bit # platforms (LFS, if supported by the # operating system): yes or no. USE_LARGEFILE:= yes INSTALL_PATH := /usr/local/bin ifeq ($(USE_LARGEFILE),yes) # these flags work for linux / glibc. # change for others, if necessary. FILESIZE_DEFS:= -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 else FILESIZE_DEFS:= endif ####### Files BINARY := lxsplit HEADERS := config.h func.h merge.h split.h SOURCES := func.c merge.c split.c main.c mkuoff_t.c OBJECTS := func.o merge.o split.o main.o ####### Implicit rules .SUFFIXES: .c .c.o: $(CC) -c $(CFLAGS) $(FILESIZE_DEFS) -I$(INCPATH) -o $@ $< ####### Build rules all: $(BINARY) $(BINARY): $(OBJECTS) $(CC) $(LDFLAGS) -o $(BINARY) $(OBJECTS) $(LDLIBS) uoff_t.h: mkuoff_t.c $(CC) $(CFLAGS) $(FILESIZE_DEFS) -o mkuoff_t mkuoff_t.c @echo "Generating uoff_t.h" @./mkuoff_t clean: -rm -f core *.o mkuoff_t uoff_t.h # -rm -f $(BINARY) install: cp $(BINARY) $(INSTALL_PATH) uninstall: rm $(INSTALL_PATH)/$(BINARY) ####### Dependencies func.o: uoff_t.h func.c func.h config.h main.o: uoff_t.h main.c merge.h split.h config.h merge.o: uoff_t.h merge.c func.h merge.h config.h split.o: uoff_t.h split.c split.h func.h config.h lxsplit-0.2.4/func.c0000664000076400007640000000473011032733714013414 0ustar ozzieozzie/* * $Id: func.c,v 1.7 2008/07/02 17:15:56 sezero Exp $ * This file is a part of the lxSplit tool sources. * * Copyright (c) 2001 Richard Stellingwerff * Copyright (c) 2008 O. Sezer * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to: * * Free Software Foundation, Inc. * 51 Franklin St, Fifth Floor, * Boston, MA 02110-1301 USA */ #include #include #include #include #if 0 /* statfs icludes: */ #if (defined(__APPLE__) && defined(__MACH__)) /* Mac OS X */ || \ defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) #include #include #else /* BSD */ #include #endif /* Linux, etc. */ #endif #include #include #include #include "config.h" #include "func.h" #if 0 uintmax_t available_diskspace (const char *path) { struct statfs buf; uintmax_t space; if (statfs(path, &buf) < 0) return 0; space = buf.f_bsize; space *= buf.f_bavail; return space; } #endif char *strip_path (const char *cfilename) { size_t lpos, i, n, len; char *filename; lpos = 0; len = strlen(cfilename); for (i = 0; i < len; i++) if (cfilename[i] == '/') lpos = i; if (lpos != 0) lpos++; n = 0; filename = (char *)malloc((len + 2) * sizeof(char)); for (i = lpos; i < len; i++) { filename[n] = cfilename[i]; n++; } filename[n] = '\0'; return filename; } char *shorten_path (const char *cfilename) { char *filename; size_t i, n, len; len = strlen(cfilename); if (len < 30) return (char *)cfilename; filename = (char *)malloc((30 + 1) * sizeof(char)); n = 0; for (i = 0; i < 10; i++) { filename[n] = cfilename[i]; n++; } for (i = 0; i < 3; i++) { filename[n] = '.'; n++; } for (i = len - 17; i < len; i++) { filename[n] = cfilename[i]; n++; } filename[30] = '\0'; return filename; } lxsplit-0.2.4/config.h0000664000076400007640000000461011071405204013721 0ustar ozzieozzie/* * $Id: config.h,v 1.10 2008/10/03 12:05:24 sezero Exp $ * This file is a part of the lxSplit tool sources. * * Copyright (c) 2001 Richard Stellingwerff * Copyright (c) 2008 O. Sezer * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to: * * Free Software Foundation, Inc. * 51 Franklin St, Fifth Floor, * Boston, MA 02110-1301 USA */ #ifndef __CONFIG_H #define __CONFIG_H /* version macros: */ #define LXSPLIT_VER_MAJ 0 #define LXSPLIT_VER_MID 2 #define LXSPLIT_VER_MIN 4 #include #if defined(__cplusplus) #define __STDC_CONSTANT_MACROS 1 #define __STDC_FORMAT_MACROS 1 #endif /* __cplusplus */ #include #include #undef USE_LFS_SUPPORT /* type sizes and 'unsigned off_t': */ #include "uoff_t.h" #if !defined(PRIuLEAST32) # define PRIuLEAST32 "u" #endif #if !defined(PRIuLEAST64) # if (SIZEOF_LONG < 8) # define PRIuLEAST64 "llu" # else # define PRIuLEAST64 "lu" # endif #endif #if !defined(UINT64_C) # if (SIZEOF_LONG < 8) # define UINT64_C(c) c ## ULL # else # define UINT64_C(c) c ## UL # endif #endif #if (SIZEOF_UOFF_T < 8) /* No LFS : */ # define _STRTOULL strtoul # define _PRI_ULL_ PRIuLEAST32 typedef unsigned long int strtou_t; #else /* Use LFS : */ # define USE_LFS_SUPPORT 1 # define _PRI_ULL_ PRIuLEAST64 # if (SIZEOF_LONG < 8) # define _STRTOULL strtoumax typedef uoff_t strtou_t; # else # define _STRTOULL strtoul typedef unsigned long int strtou_t; # endif #endif /* maximum size for split files: */ #if !defined(USE_LFS_SUPPORT) #define MAX_SPLITSIZE (2147483647U) /* 2 GB - 1 == (1U << 31) - 1 */ #else #define MAX_SPLITSIZE (UINT64_C(1) << 33) /* 8 GB == 8589934592 bytes. shall I even need this much? */ #endif /* read buffer size */ #define READ_BUFSIZE 4096U #endif /* __CONFIG_H */ lxsplit-0.2.4/merge.c0000664000076400007640000001121510751021753013554 0ustar ozzieozzie/* * $Id: merge.c,v 1.9 2008/02/02 08:03:55 sezero Exp $ * This file is a part of the lxSplit tool sources. * * Copyright (c) 2001 Richard Stellingwerff * Copyright (c) 2008 O. Sezer * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to: * * Free Software Foundation, Inc. * 51 Franklin St, Fifth Floor, * Boston, MA 02110-1301 USA */ #include #include #include #include #include #include #include "config.h" #include "func.h" #include "merge.h" int merge_files (const char *filename) { FILE *fp_split, *fp_merged; size_t len, bytes_read; uoff_t merged_size, split_size, split_pos; int filenr, amount, startnr; char *merged_fname, *split_fname, *orig_fname, *missing_fname, *c_bytes, *split_sfname; struct stat buf; len = strlen(filename); if (len < 5 || filename[len - 4] != '.') { printf("Erroneous filename. Please supply the extension.\n" "Must end with .000 or .001\n"); return 1; } switch (filename[len - 1]) { case '0': startnr = 0; break; case '1': startnr = 1; break; default: printf("Erroneous filename. Please supply the extension.\n" "Must end with .000 or .001\n"); return 1; } orig_fname = (char *)malloc((len - 4 + 1) * sizeof(char)); split_fname = (char *)malloc((len + 1) * sizeof(char)); strncpy(orig_fname, filename, len - 4); orig_fname[len - 4] = '\0'; merged_fname = strip_path(orig_fname); amount = 0; merged_size = 0; missing_fname = NULL; for (filenr = startnr; filenr < 1000; filenr++) { if (filenr < 10) sprintf(split_fname, "%s.00%d", orig_fname, filenr); else if (filenr < 100) sprintf(split_fname, "%s.0%d", orig_fname, filenr); else /* if (filenr < 1000) 999 is hardcoded above already. */ sprintf(split_fname, "%s.%d", orig_fname, filenr); if (stat(split_fname, &buf) == -1) { if (filenr == startnr) { printf("Can't find `%s'\n", split_fname); return 1; } else { if (missing_fname == NULL) missing_fname = strdup(split_fname); } } else { if (!S_ISREG(buf.st_mode)) { printf("Can't find `%s'\n", split_fname); return 1; } else { if (missing_fname != NULL) { printf("Missing file `%s' !\n", missing_fname); return 1; } merged_size += buf.st_size; amount++; } } } printf("Creating merged file `%s'.\nComplete size: %" _PRI_ULL_ " in %d files.\n", merged_fname, merged_size, amount); if (stat(merged_fname, &buf) == 0) { printf("%s already exists! Aborting...\n", merged_fname); return 1; } fp_merged = fopen(merged_fname, "w"); if (fp_merged == NULL) { perror("cannot create output file"); return 1; } c_bytes = (char *)malloc(READ_BUFSIZE * sizeof(char)); for (filenr = startnr; filenr <= amount + (startnr - 1); filenr++) { if (filenr < 10) sprintf(split_fname, "%s.00%d", orig_fname, filenr); else if (filenr < 100) sprintf(split_fname, "%s.0%d", orig_fname, filenr); else if (filenr < 1000) sprintf(split_fname, "%s.%d", orig_fname, filenr); split_sfname = shorten_path(split_fname); printf("Processing file `%s' ...\n", split_sfname); if (stat(split_fname, &buf) == -1) { perror("cannot stat input file"); goto _err_in; } split_size = buf.st_size; fp_split = fopen(split_fname, "r"); if (fp_split == NULL) { perror("cannot open input file"); goto _err_in; } split_pos = 0; while (split_pos < split_size) { bytes_read = fread(c_bytes, 1, READ_BUFSIZE, fp_split); if (bytes_read != READ_BUFSIZE && !feof(fp_split)) { perror("error while reading input file"); goto _err_io; } len = fwrite(c_bytes, 1, bytes_read, fp_merged); if (len != bytes_read) { perror("error while writing to output file"); goto _err_io; } split_pos += bytes_read; } fclose(fp_split); if (split_sfname != split_fname) free (split_sfname); } printf("Done!\n"); fclose(fp_merged); return 0; _err_io: fclose(fp_split); _err_in: fclose(fp_merged); return 1; } lxsplit-0.2.4/merge.h0000664000076400007640000000205610751017632013565 0ustar ozzieozzie/* * $Id: merge.h,v 1.3 2008/02/02 07:45:30 sezero Exp $ * This file is a part of the lxSplit tool sources. * * Copyright (c) 2001 Richard Stellingwerff * Copyright (c) 2008 O. Sezer * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to: * * Free Software Foundation, Inc. * 51 Franklin St, Fifth Floor, * Boston, MA 02110-1301 USA */ #ifndef __MERGE_H #define __MERGE_H int merge_files (const char *filename); #endif /* __MERGE_H */ lxsplit-0.2.4/README0000664000076400007640000000445111071405540013171 0ustar ozzieozzie lxSplit for Unix (Linux, BSD, ...) version 0.2.4 http://lxsplit.sourceforge.net/ http://sourceforge.net/projects/lxsplit/ ------------------------------------------------------------------------ This utility is used to split up huge files into smaller pieces without compression. It can be used to join the splitted pieces back into the original file. LXSplit is fully compatible with HJSplit which is a free tool available for other operating systems (see http://www.freebyte.com) Installation is easy, just run: make make install The program will be installed as "lxsplit" in /usr/local/bin by default. If you wish to install it elsewhere, edit the Makefile, and change the 'INSTALL_PATH'. LXSplit splits and merges files with the -s and -j flags respectively. Starting with version 0.2.1, LXSplit can handle large files (>= 4 GB) both when splitting and joining. Example: To split a big file into smaller pieces of 15 MB each, run the following command: > lxsplit -s hugefile.bin 15M Output size can be given in (M)egabytes, (k)ilobytes and (b)ytes. To merge (join) the already split pieces into the original big file, run this command: > lxsplit -j smallfiles.bin.001 All resulting files (from either splitting or joining) will be placed in the current directory. ------------------------------------------------------------------------ If there are any problems with this software, or if you have suggestions or patches, visit the project page at our sourceforge.net address above: use the forums and the tracker system to get help and / or to make a bug report or submit a patch. ------------------------------------------------------------------------ LICENSE: This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. See the GNU General Public License for more details. ------------------------------------------------------------------------ Original author: Richard Stellingwerff homepage: http://www.stellingwerff.com/ Maintained by: O. Sezer ------------------------------------------------------------------------ $Id: README,v 1.12 2008/10/03 12:09:04 sezero Exp $ lxsplit-0.2.4/ChangeLog0000664000076400007640000000326311071405540014063 0ustar ozzieozzie2008-10-03, version 0.2.4, O. Sezer - split: if the input is not a regular file, give up immediately. - main: updated the help output (authors, website.) 2008-07-02, version 0.2.3, O. Sezer - fixed build problems under Mac OS X. - honor user CFLAGS. honor the CFLAGS when generating uoff_t.h. 2008-03-22, version 0.2.2, O. Sezer - invoking make with more than one jobs does not fail anymore. no other code changes. 2008-02-02, version 0.2.1, O. Sezer - LFS: large files > 4 GB are now properly supported. 2008-02-02, version 0.2.0, O. Sezer - License changed to GPLv2+ (thanks Richard!) 2008-01-31, version 0.1.4, O. Sezer - removed some unnecessary strdup() calls. - split_file(): used calculated values as size arguments to malloc() instead of the arbitrary numbers such as 200. - freed the shortened name at the end of each cycle of the loop if it is really shortened. - a few other minor things. 2008-01-30, version 0.1.3, O. Sezer - added a missing null check for the merge operation output file. - added error checks to fread and fwrite operations. - replaced a weird bounds check with a more understandable one. - uniform error messages. - removed two unused vars. 2008-01-28, version 0.1.2, O. Sezer - Fixed some wrong sizeof usage (sizef(char), not sizeof(char*)). - Limited split file size to UINT_MAX. - Switched to size_t type for size data types instead of ints. - Split size given as exact number of bytes without 'b' or 'B' is now accepted. - Licence: BSD. - Maintainance / code clean-up. 2001-08-16, version 0.1.1, Richard Stellingwerff - Removed the configure stuff, so now it should compile nicely on BSD as well. 2001-07-18, version 0.1, Richard Stellingwerff - Initial Release. lxsplit-0.2.4/func.h0000664000076400007640000000222611032733714013417 0ustar ozzieozzie/* * $Id: func.h,v 1.6 2008/07/02 17:15:56 sezero Exp $ * This file is a part of the lxSplit tool sources. * * Copyright (c) 2001 Richard Stellingwerff * Copyright (c) 2008 O. Sezer * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to: * * Free Software Foundation, Inc. * 51 Franklin St, Fifth Floor, * Boston, MA 02110-1301 USA */ #ifndef __FUNC_H #define __FUNC_H #if 0 uintmax_t available_diskspace (const char *path); #endif char *strip_path (const char *filename); char *shorten_path (const char *cfilename); #endif /* __FUNC_H */ lxsplit-0.2.4/lxsplit.spec0000664000076400007640000000245011071407526014667 0ustar ozzieozzie# RPM spec file for RedHat and Fedora # $Id: lxsplit.spec,v 1.5 2008/10/03 12:25:58 sezero Exp $ %define name lxsplit %define version 0.2.4 Name: %{name} Summary: File split / merge utility Version: %{version} Release: 1 Source: http://download.sourceforge.net/lxsplit/%{name}-%{version}.tar.gz URL: http://lxsplit.sourceforge.net/ Group: Applications/File BuildRoot: %{_tmppath}/%{name}-%{version}-build License: GPLv2+ %description lxSplit is a simple tool for splitting files and joining the splitted files on unix-like platforms, such as Linux, FreeBSD, OpenBSD, etc. Splitting is done without compression and large files (> 4 GB) are supported. lxSplit is fully compatible with the HJSplit utility which is available for other operating systems. %prep %setup -q %build %{__make} %install %{__rm} -rf %{buildroot} %{__mkdir_p} %{buildroot}/%{_bindir} %{__install} -D -m755 %{name} %{buildroot}/%{_bindir}/%{name} %clean %{__rm} -rf %{buildroot} %files %defattr(0755,root,root) %{_bindir}/%{name} %changelog * Wed Oct 03 2008 sezero 0.2.4-1 - v0.2.4 * Wed Jul 02 2008 sezero 0.2.3-1 - v0.2.3 * Mon Mar 22 2008 sezero 0.2.2-1 - v0.2.2 * Mon Feb 04 2008 sezero 0.2.1-1 - v0.2.1 lxsplit-0.2.4/split.h0000664000076400007640000000207010751021753013614 0ustar ozzieozzie/* * $Id: split.h,v 1.4 2008/02/02 08:03:55 sezero Exp $ * This file is a part of the lxSplit tool sources. * * Copyright (c) 2001 Richard Stellingwerff * Copyright (c) 2008 O. Sezer * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to: * * Free Software Foundation, Inc. * 51 Franklin St, Fifth Floor, * Boston, MA 02110-1301 USA */ #ifndef __SPLIT_H #define __SPLIT_H int split_file (const char *filename, uoff_t _s); #endif /* __SPLIT_H */ lxsplit-0.2.4/split.c0000664000076400007640000001042711071405107013607 0ustar ozzieozzie/* * $Id: split.c,v 1.11 2008/10/03 12:04:23 sezero Exp $ * This file is a part of the lxSplit tool sources. * * Copyright (c) 2001 Richard Stellingwerff * Copyright (c) 2008 O. Sezer * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to: * * Free Software Foundation, Inc. * 51 Franklin St, Fifth Floor, * Boston, MA 02110-1301 USA */ #include #include #include #include #include #include #include "config.h" #include "func.h" #include "split.h" int split_file (const char *filename, uoff_t _s) { FILE *fp_orig, *fp_split; uoff_t orig_pos, orig_size, split_pos, split_size, bytes_left, piece_bytes; size_t bytes_read, allow_read, len; int filenr, pieces; struct stat buf; char *c_byte, *split_fname, *orig_fname, *split_sfname; orig_pos = orig_size = 0; split_pos = split_size = 0; filenr = 1; if (stat(filename, &buf) == -1) { perror("cannot stat input file"); return 1; } if (!S_ISREG(buf.st_mode)) { printf("%s is not a regular file\n", filename); return 1; } orig_size = buf.st_size; if (_s >= orig_size) { printf("Splitted filesize is same as size of the filename!\n" "Try using cp(1) instead...\n"); return 1; } fp_orig = fopen(filename, "r"); if (fp_orig == NULL) { perror("error opening input file"); return -1; } split_size = _s; bytes_left = orig_size; pieces = orig_size / split_size; if ((orig_size % split_size) > 0) pieces++; if (pieces > 999) { printf("You will be ending up with over %d files, while I" "rather wouldn't go over the 999... Perhaps you" "could choose a bigger output size?\n", pieces); return 1; } orig_fname = strip_path(filename); len = strlen(orig_fname) + 5; /* ".001" + null terminator */ split_fname = (char *) malloc(len * sizeof(char)); c_byte = (char *) malloc(READ_BUFSIZE * sizeof(char)); printf("Splitting %s into %d pieces.\n", orig_fname, pieces); while (orig_pos < orig_size) { if (filenr < 10) sprintf(split_fname, "%s.00%d", orig_fname, filenr); else if (filenr < 100) sprintf(split_fname, "%s.0%d", orig_fname, filenr); else /* if (filenr < 1000) 999 is hardcoded above already. */ sprintf(split_fname, "%s.%d", orig_fname, filenr); fp_split = fopen(split_fname, "w"); if (fp_split == NULL) { perror("cannot create output file"); goto _err_of; } split_pos = 0; split_sfname = shorten_path(split_fname); printf("%s\t\t\t%" _PRI_ULL_ " bytes\n", split_sfname, split_size); bytes_read = 0; allow_read = READ_BUFSIZE; while (split_pos < split_size) { piece_bytes = split_size - split_pos; /* how much to read */ if (piece_bytes < (uoff_t)allow_read) allow_read = (size_t)piece_bytes; bytes_read = fread(c_byte, 1, allow_read, fp_orig); /* how much is read */ if (bytes_read != allow_read) { if (feof(fp_orig)) printf("unexpected EOF!...\n"); perror("error while reading input file"); goto _err_io; } len = fwrite(c_byte, 1, bytes_read, fp_split); if (len != bytes_read) { perror("error while writing to output file"); goto _err_io; } orig_pos += bytes_read; split_pos += bytes_read; #ifdef DEBUG printf("split pos :\t%" _PRI_ULL_ "\n", split_pos); printf("split size:\t%" _PRI_ULL_ "\n", split_size); printf("allow_read:\t%lu\n", (unsigned long)allow_read); sleep (1); #endif } bytes_left -= split_size; if (bytes_left < split_size) split_size = bytes_left; filenr++; fclose(fp_split); if (split_sfname != split_fname) free (split_sfname); } printf("Done!\n"); fclose(fp_orig); return 0; _err_io: fclose(fp_split); _err_of: fclose(fp_orig); return 1; } lxsplit-0.2.4/main.c0000664000076400007640000000712611071405001013373 0ustar ozzieozzie/* * $Id: main.c,v 1.5 2008/10/03 12:03:13 sezero Exp $ * This file is a part of the lxSplit tool sources. * * Copyright (c) 2001 Richard Stellingwerff * Copyright (c) 2008 O. Sezer * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to: * * Free Software Foundation, Inc. * 51 Franklin St, Fifth Floor, * Boston, MA 02110-1301 USA */ #include #include #include #include #include #include #include #include "config.h" #include "split.h" #include "merge.h" static const char authors[] = "Richard Stellingwerff, O. Sezer"; static const char website[] = "http://lxsplit.sourceforge.net/"; static void print_help (const char *cmd) { printf ("LXSplit v%d.%d.%d by %s.\nHome page: %s\n\n", LXSPLIT_VER_MAJ, LXSPLIT_VER_MID, LXSPLIT_VER_MIN, authors, website); printf ("Usage: %s [OPTION] [FILE] [SPLITSIZE]\n\n", cmd); printf ("Available options:\n" " -j : join the files beginning with the given name\n" " -s : split the given file. requires a valid size\n" "Splitsize examples: 15M, 100m, 5000k, 30000000b\n\n"); printf ("Examples:\n" "\t%s -s hugefile.bin 15M\n" "\t%s -j hugefile.bin.001\n\n", cmd, cmd); } int main (int argc, char **argv) { char *filename, *usersize; int ret; strtou_t size; size_t len; if (argc < 3) { print_help(argv[0]); exit (1); } if (!strcmp(argv[1], "-s")) { if (argc != 4) { print_help(argv[0]); exit (1); } if (argv[3][0] == '-') { printf("Split size cannot be a negative number!\n\n"); exit (1); } len = strlen(argv[3]); usersize = (char *)malloc((len + 1) * sizeof(char)); strncpy(usersize, argv[3], len); if ((argv[3][len - 1] == 'M') || (argv[3][len - 1] == 'm')) { usersize[len - 1] = '\0'; size = _STRTOULL(usersize, NULL, 10); size *= 1024 * 1024; } else if ((argv[3][len - 1] == 'K') || (argv[3][len - 1] == 'k')) { usersize[len - 1] = '\0'; size = _STRTOULL(usersize, NULL, 10); size *= 1024; } else if ((argv[3][len - 1] == 'B' || argv[3][len - 1] == 'b')) { usersize[len - 1] = '\0'; size = _STRTOULL(usersize, NULL, 10); } else if (isdigit(argv[3][len - 1])) { size = _STRTOULL(usersize, NULL, 10); } else { printf("Please specify the size correctly!\n\n"); print_help(argv[0]); exit (1); } /* printf ("size == %" _PRI_ULL_ "\n", size); */ if (size == 0) { printf("Invalid split size (0). Did you enter a very large number?\n\n"); exit (1); } if (size > MAX_SPLITSIZE) { printf("Split size can be %" _PRI_ULL_ " bytes at maximum!\n\n", (uoff_t)MAX_SPLITSIZE); exit (1); } filename = strdup(argv[2]); ret = split_file(filename, size); exit (ret); } else if (!strcmp(argv[1], "-j")) { if (argc != 3) { print_help(argv[0]); exit (1); } filename = strdup(argv[2]); ret = merge_files(filename); exit (ret); } else { printf("Whatcha wanna do?\n"); print_help(argv[0]); exit (1); } exit (0); } lxsplit-0.2.4/COPYING0000664000076400007640000004310610751017632013351 0ustar ozzieozzie GNU GENERAL PUBLIC LICENSE Version 2, June 1991 Copyright (C) 1989, 1991 Free Software Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This General Public License applies to most of the Free Software Foundation's software and to any other program whose authors commit to using it. (Some other Free Software Foundation software is covered by the GNU Lesser General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. Finally, any free program is threatened constantly by software patents. We wish to avoid the danger that redistributors of a free program will individually obtain patent licenses, in effect making the program proprietary. To prevent this, we have made it clear that any patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any derivative work under copyright law: that is to say, a work containing the Program or a portion of it, either verbatim or with modifications and/or translated into another language. (Hereinafter, translation is included without limitation in the term "modification".) Each licensee is addressed as "you". Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running the Program is not restricted, and the output from the Program is covered only if its contents constitute a work based on the Program (independent of having been made by running the Program). Whether that is true depends on what the Program does. 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and give any other recipients of the Program a copy of this License along with the Program. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Program or any portion of it, thus forming a work based on the Program, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) You must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. b) You must cause any work that you distribute or publish, that in whole or in part contains or is derived from the Program or any part thereof, to be licensed as a whole at no charge to all third parties under the terms of this License. c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the most ordinary way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this License. (Exception: if the Program itself is interactive but does not normally print such an announcement, your work based on the Program is not required to print an announcement.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Program, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Program, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Program. In addition, mere aggregation of another work not based on the Program with the Program (or with a work based on the Program) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may copy and distribute the Program (or a work based on it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you also do one of the following: a) Accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, b) Accompany it with a written offer, valid for at least three years, to give any third party, for a charge no more than your cost of physically performing source distribution, a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange; or, c) Accompany it with the information you received as to the offer to distribute corresponding source code. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form with such an offer, in accord with Subsection b above.) The source code for a work means the preferred form of the work for making modifications to it. For an executable work, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the executable. However, as a special exception, the source code distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. If distribution of executable or object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place counts as distribution of the source code, even though third parties are not compelled to copy the source along with the object code. 4. You may not copy, modify, sublicense, or distribute the Program except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense or distribute the Program is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 5. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Program or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Program (or any work based on the Program), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Program or works based on it. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties to this License. 7. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Program at all. For example, if a patent license would not permit royalty-free redistribution of the Program by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Program. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system, which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 8. If the distribution and/or use of the Program is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Program under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 9. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of this License, you may choose any version ever published by the Free Software Foundation. 10. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) year name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (which makes passes at compilers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License.