split.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. * dpkg-split - splitting and joining of multipart *.deb archives
  3. * split.c - splitting archives
  4. *
  5. * Copyright (C) 1995 Ian Jackson <ian@chiark.greenend.org.uk>
  6. *
  7. * This is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as
  9. * published by the Free Software Foundation; either version 2,
  10. * or (at your option) any later version.
  11. *
  12. * This is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public
  18. * License along with dpkg; if not, write to the Free Software
  19. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  20. */
  21. #include <config.h>
  22. #include <stdio.h>
  23. #include <stdlib.h>
  24. #include <limits.h>
  25. #include <assert.h>
  26. #include <unistd.h>
  27. #include <string.h>
  28. #include <sys/stat.h>
  29. #include <fcntl.h>
  30. #include <dpkg.h>
  31. #include <dpkg-db.h>
  32. #include "dpkg-split.h"
  33. void do_split(const char *const *argv) {
  34. const char *sourcefile, *prefix;
  35. char *palloc;
  36. int l, fd;
  37. char partsizebuf[30], lengthbuf[30], partsizeallowbuf[30];
  38. struct stat stab;
  39. sourcefile= *argv++;
  40. if (!sourcefile)
  41. badusage(_("--split needs a source filename argument"));
  42. prefix= *argv++;
  43. if (prefix && *argv)
  44. badusage(_("--split takes at most a source filename and destination prefix"));
  45. if (!prefix) {
  46. l= strlen(sourcefile);
  47. palloc= nfmalloc(l+1);
  48. strcpy(palloc,sourcefile);
  49. if (!strcmp(palloc+l-(sizeof(DEBEXT)-1),DEBEXT)) {
  50. l -= (sizeof(DEBEXT)-1);
  51. palloc[l]= 0;
  52. }
  53. prefix= palloc;
  54. }
  55. sprintf(partsizebuf,"%ld",maxpartsize-HEADERALLOWANCE);
  56. sprintf(partsizeallowbuf,"%ld",maxpartsize);
  57. fd= open(sourcefile,O_RDONLY);
  58. if (!fd) ohshite(_("unable to open source file `%.250s'"),sourcefile);
  59. if (fstat(fd,&stab)) ohshite(_("unable to fstat source file"));
  60. if (!S_ISREG(stab.st_mode)) ohshit(_("source file `%.250s' not a plain file"),sourcefile);
  61. sprintf(lengthbuf,"%lu",(unsigned long)stab.st_size);
  62. m_dup2(fd,0);
  63. execl(MKSPLITSCRIPT,MKSPLITSCRIPT,
  64. sourcefile,partsizebuf,prefix,lengthbuf,partsizeallowbuf,msdos?"yes":"no",
  65. NULL);
  66. ohshite(_("unable to exec mksplit"));
  67. }