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

Function cupsFileOpen

cups/file.c:1078–1183  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1076 */
1077
1078cups_file_t * /* O - CUPS file or @code NULL@ if the file or socket cannot be opened */
1079cupsFileOpen(const char *filename, /* I - Name of file */
1080 const char *mode) /* I - Open mode */
1081{
1082 cups_file_t *fp; /* New CUPS file */
1083 int fd; /* File descriptor */
1084 char hostname[1024], /* Hostname */
1085 *portname; /* Port "name" (number or service) */
1086 http_addrlist_t *addrlist; /* Host address list */
1087
1088
1089 DEBUG_printf(("cupsFileOpen(filename=\"%s\", mode=\"%s\")", filename,
1090 mode));
1091
1092 /*
1093 * Range check input...
1094 */
1095
1096 if (!filename || !mode ||
1097 (*mode != 'r' && *mode != 'w' && *mode != 'a' && *mode != 's') ||
1098 (*mode == 'a' && isdigit(mode[1] & 255)))
1099 return (NULL);
1100
1101 /*
1102 * Open the file...
1103 */
1104
1105 switch (*mode)
1106 {
1107 case 'a' : /* Append file */
1108 fd = cups_open(filename, O_WRONLY | O_CREAT | O_APPEND | O_LARGEFILE | O_BINARY);
1109 break;
1110
1111 case 'r' : /* Read file */
1112 fd = open(filename, O_RDONLY | O_LARGEFILE | O_BINARY, 0);
1113 break;
1114
1115 case 'w' : /* Write file */
1116 fd = cups_open(filename, O_WRONLY | O_LARGEFILE | O_BINARY);
1117 if (fd < 0 && errno == ENOENT)
1118 {
1119 fd = cups_open(filename, O_WRONLY | O_CREAT | O_EXCL | O_LARGEFILE | O_BINARY);
1120 if (fd < 0 && errno == EEXIST)
1121 fd = cups_open(filename, O_WRONLY | O_LARGEFILE | O_BINARY);
1122 }
1123
1124 if (fd >= 0)
1125#ifdef _WIN32
1126 _chsize(fd, 0);
1127#else
1128 ftruncate(fd, 0);
1129#endif /* _WIN32 */
1130 break;
1131
1132 case 's' : /* Read/write socket */
1133 strlcpy(hostname, filename, sizeof(hostname));
1134 if ((portname = strrchr(hostname, ':')) != NULL)
1135 *portname++ = '\0';

Callers 15

mainFunction · 0.85
do_testFunction · 0.85
mime_load_convsFunction · 0.85
mime_load_typesFunction · 0.85
cupsdCheckLogFileFunction · 0.85
mainFunction · 0.85
get_fileFunction · 0.85
list_ppdsFunction · 0.85
load_ppdsFunction · 0.85
load_ppds_datFunction · 0.85
install_cupsd_confFunction · 0.85
read_cups_files_confFunction · 0.85

Calls 6

cups_openFunction · 0.85
httpAddrGetListFunction · 0.85
httpAddrConnectFunction · 0.85
httpAddrFreeListFunction · 0.85
cupsFileOpenFdFunction · 0.85
httpAddrCloseFunction · 0.85

Tested by 8

mainFunction · 0.68
check_basicsFunction · 0.68
mainFunction · 0.68
print_fileFunction · 0.68
mainFunction · 0.68
mainFunction · 0.68
random_testsFunction · 0.68
read_write_testsFunction · 0.68