split.c 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * dpkg-split - splitting and joining of multipart *.deb archives
  3. * split.c - splitting archives
  4. *
  5. * Copyright © 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 <compat.h>
  23. #include <dpkg-i18n.h>
  24. #include <myopt.h>
  25. #include <stdio.h>
  26. #include <stdlib.h>
  27. #include <limits.h>
  28. #include <assert.h>
  29. #include <unistd.h>
  30. #include <string.h>
  31. #include <sys/stat.h>
  32. #include <fcntl.h>
  33. #include <dpkg.h>
  34. #include <dpkg-db.h>
  35. #include "dpkg-split.h"
  36. void do_split(const char *const *argv) {
  37. const char *sourcefile, *prefix;
  38. char *palloc;
  39. int l, fd;
  40. char partsizebuf[30], lengthbuf[30], partsizeallowbuf[30];
  41. struct stat stab;
  42. sourcefile= *argv++;
  43. if (!sourcefile)
  44. badusage(_("--split needs a source filename argument"));
  45. prefix= *argv++;
  46. if (prefix && *argv)
  47. badusage(_("--split takes at most a source filename and destination prefix"));
  48. if (!prefix) {
  49. l= strlen(sourcefile);
  50. palloc= nfmalloc(l+1);
  51. strcpy(palloc,sourcefile);
  52. if (!strcmp(palloc+l-(sizeof(DEBEXT)-1),DEBEXT)) {
  53. l -= (sizeof(DEBEXT)-1);
  54. palloc[l]= 0;
  55. }
  56. prefix= palloc;
  57. }
  58. sprintf(partsizebuf,"%ld",maxpartsize-HEADERALLOWANCE);
  59. sprintf(partsizeallowbuf,"%ld",maxpartsize);
  60. fd= open(sourcefile,O_RDONLY);
  61. if (!fd) ohshite(_("unable to open source file `%.250s'"),sourcefile);
  62. if (fstat(fd,&stab)) ohshite(_("unable to fstat source file"));
  63. if (!S_ISREG(stab.st_mode)) ohshit(_("source file `%.250s' not a plain file"),sourcefile);
  64. sprintf(lengthbuf,"%lu",(unsigned long)stab.st_size);
  65. m_dup2(fd,0);
  66. execl(MKSPLITSCRIPT,MKSPLITSCRIPT,
  67. sourcefile,partsizebuf,prefix,lengthbuf,partsizeallowbuf,msdos?"yes":"no",
  68. NULL);
  69. ohshite(_("unable to exec mksplit"));
  70. }