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

Function cupsFileFind

cups/file.c:511–603  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

509 */
510
511const char * /* O - Full path to file or @code NULL@ if not found */
512cupsFileFind(const char *filename, /* I - File to find */
513 const char *path, /* I - Colon/semicolon-separated path */
514 int executable, /* I - 1 = executable files, 0 = any file/dir */
515 char *buffer, /* I - Filename buffer */
516 int bufsize) /* I - Size of filename buffer */
517{
518 char *bufptr, /* Current position in buffer */
519 *bufend; /* End of buffer */
520
521
522 /*
523 * Range check input...
524 */
525
526 DEBUG_printf(("cupsFileFind(filename=\"%s\", path=\"%s\", executable=%d, buffer=%p, bufsize=%d)", filename, path, executable, (void *)buffer, bufsize));
527
528 if (!filename || !buffer || bufsize < 2)
529 return (NULL);
530
531 if (!path)
532 {
533 /*
534 * No path, so check current directory...
535 */
536
537 if (!access(filename, 0))
538 {
539 strlcpy(buffer, filename, (size_t)bufsize);
540 return (buffer);
541 }
542 else
543 return (NULL);
544 }
545
546 /*
547 * Now check each path and return the first match...
548 */
549
550 bufend = buffer + bufsize - 1;
551 bufptr = buffer;
552
553 while (*path)
554 {
555#ifdef _WIN32
556 if (*path == ';' || (*path == ':' && ((bufptr - buffer) > 1 || !isalpha(buffer[0] & 255))))
557#else
558 if (*path == ';' || *path == ':')
559#endif /* _WIN32 */
560 {
561 if (bufptr > buffer && bufptr[-1] != '/' && bufptr < bufend)
562 *bufptr++ = '/';
563
564 strlcpy(bufptr, filename, (size_t)(bufend - bufptr));
565
566#ifdef _WIN32
567 if (!access(buffer, 0))
568#else

Callers 4

exec_programFunction · 0.85
mime_add_fcacheFunction · 0.85
mainFunction · 0.85

Calls

no outgoing calls

Tested by 1

mainFunction · 0.68