split.c 2.4 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
  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 <stdio.h>
  25. #include <stdlib.h>
  26. #include <limits.h>
  27. #include <unistd.h>
  28. #include <string.h>
  29. #include <sys/stat.h>
  30. #include <fcntl.h>
  31. #include <dpkg/dpkg.h>
  32. #include <dpkg/dpkg-db.h>
  33. #include <dpkg/myopt.h>
  34. #include "dpkg-split.h"
  35. void do_split(const char *const *argv) {
  36. const char *sourcefile, *prefix;
  37. char *palloc;
  38. int l, fd;
  39. char partsizebuf[30], lengthbuf[30], partsizeallowbuf[30];
  40. struct stat stab;
  41. sourcefile= *argv++;
  42. if (!sourcefile)
  43. badusage(_("--split needs a source filename argument"));
  44. prefix= *argv++;
  45. if (prefix && *argv)
  46. badusage(_("--split takes at most a source filename and destination prefix"));
  47. if (!prefix) {
  48. l= strlen(sourcefile);
  49. palloc= nfmalloc(l+1);
  50. strcpy(palloc,sourcefile);
  51. if (!strcmp(palloc+l-(sizeof(DEBEXT)-1),DEBEXT)) {
  52. l -= (sizeof(DEBEXT)-1);
  53. palloc[l] = '\0';
  54. }
  55. prefix= palloc;
  56. }
  57. sprintf(partsizebuf,"%ld",maxpartsize-HEADERALLOWANCE);
  58. sprintf(partsizeallowbuf,"%ld",maxpartsize);
  59. fd= open(sourcefile,O_RDONLY);
  60. if (fd < 0)
  61. 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. }