MCPcopy Create free account
hub / github.com/OpenPrinting/cups / cups_open

Function cups_open

cups/file.c:2675–2753  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2673 */
2674
2675static int /* O - File descriptor or -1 otherwise */
2676cups_open(const char *filename, /* I - Filename */
2677 int mode) /* I - Open mode */
2678{
2679 int fd; /* File descriptor */
2680 struct stat fileinfo; /* File information */
2681#ifndef _WIN32
2682 struct stat linkinfo; /* Link information */
2683#endif /* !_WIN32 */
2684
2685
2686 /*
2687 * Open the file...
2688 */
2689
2690 if ((fd = open(filename, mode, 0666)) < 0)
2691 return (-1);
2692
2693 /*
2694 * Then verify that the file descriptor doesn't point to a directory or hard-
2695 * linked file.
2696 */
2697
2698 if (fstat(fd, &fileinfo))
2699 {
2700 close(fd);
2701 return (-1);
2702 }
2703
2704 if (fileinfo.st_nlink != 1)
2705 {
2706 close(fd);
2707 errno = EPERM;
2708 return (-1);
2709 }
2710
2711#ifdef _WIN32
2712 if (fileinfo.st_mode & _S_IFDIR)
2713#else
2714 if (S_ISDIR(fileinfo.st_mode))
2715#endif /* _WIN32 */
2716 {
2717 close(fd);
2718 errno = EISDIR;
2719 return (-1);
2720 }
2721
2722#ifndef _WIN32
2723 /*
2724 * Then use lstat to determine whether the filename is a symlink...
2725 */
2726
2727 if (lstat(filename, &linkinfo))
2728 {
2729 close(fd);
2730 return (-1);
2731 }
2732

Callers 1

cupsFileOpenFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected