split.c 2.3 KB

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