file.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. * libdpkg - Debian packaging suite library routines
  3. * file.c - file handling functions
  4. *
  5. * Copyright © 1995 Ian Jackson <ian@chiark.greenend.org.uk>
  6. * Copyright © 2008 Guillem Jover <guillem@debian.org>
  7. *
  8. * This is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2,
  11. * or (at your option) any later version.
  12. *
  13. * This is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. #include <config.h>
  22. #include <compat.h>
  23. #include <sys/types.h>
  24. #include <sys/stat.h>
  25. #include <errno.h>
  26. #include <unistd.h>
  27. #include <dpkg/dpkg.h>
  28. #include <dpkg/i18n.h>
  29. #include <dpkg/file.h>
  30. void
  31. file_copy_perms(const char *src, const char *dst)
  32. {
  33. struct stat stab;
  34. if (stat(src, &stab) == -1) {
  35. if (errno == ENOENT)
  36. return;
  37. ohshite(_("unable to stat source file '%.250s'"), src);
  38. }
  39. if (chown(dst, stab.st_uid, stab.st_gid) == -1)
  40. ohshite(_("unable to change ownership of target file '%.250s'"),
  41. dst);
  42. if (chmod(dst, (stab.st_mode & 07777)) == -1)
  43. ohshite(_("unable to set mode of target file '%.250s'"), dst);
  44. }