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

Function mimeFileType

scheduler/type.c:586–685  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

584 */
585
586mime_type_t * /* O - Type of file */
587mimeFileType(mime_t *mime, /* I - MIME database */
588 const char *pathname, /* I - Name of file to check on disk */
589 const char *filename, /* I - Original filename or NULL */
590 int *compression) /* O - Is the file compressed? */
591{
592 _mime_filebuf_t fb; /* File buffer */
593 const char *base; /* Base filename of file */
594 mime_type_t *type, /* File type */
595 *best; /* Best match */
596
597
598 DEBUG_printf(("mimeFileType(mime=%p, pathname=\"%s\", filename=\"%s\", "
599 "compression=%p)", mime, pathname, filename, compression));
600
601 /*
602 * Range check input parameters...
603 */
604
605 if (!mime || !pathname)
606 {
607 DEBUG_puts("1mimeFileType: Returning NULL.");
608 return (NULL);
609 }
610
611 /*
612 * Try to open the file...
613 */
614
615 if ((fb.fp = cupsFileOpen(pathname, "r")) == NULL)
616 {
617 DEBUG_printf(("1mimeFileType: Unable to open \"%s\": %s", pathname,
618 strerror(errno)));
619 DEBUG_puts("1mimeFileType: Returning NULL.");
620 return (NULL);
621 }
622
623 /*
624 * Then preload the first MIME_MAX_BUFFER bytes of the file into the file
625 * buffer, returning an error if we can't read anything...
626 */
627
628 fb.offset = 0;
629 fb.length = (int)cupsFileRead(fb.fp, (char *)fb.buffer, MIME_MAX_BUFFER);
630
631 if (fb.length <= 0)
632 {
633 DEBUG_printf(("1mimeFileType: Unable to read from \"%s\": %s", pathname, strerror(errno)));
634 DEBUG_puts("1mimeFileType: Returning NULL.");
635
636 cupsFileClose(fb.fp);
637
638 return (NULL);
639 }
640
641 /*
642 * Figure out the base filename (without directory portion)...
643 */

Callers 9

cupsdReadClientFunction · 0.85
mainFunction · 0.85
add_bannerFunction · 0.85
print_jobFunction · 0.85
send_documentFunction · 0.85
cupsdLoadJobFunction · 0.85
load_job_cacheFunction · 0.85
mainFunction · 0.85
type_dirFunction · 0.85

Calls 7

cupsFileOpenFunction · 0.85
cupsFileReadFunction · 0.85
cupsFileCloseFunction · 0.85
cupsArrayFirstFunction · 0.85
cupsArrayNextFunction · 0.85
mime_check_rulesFunction · 0.85
cupsFileCompressionFunction · 0.85

Tested by 2

mainFunction · 0.68
type_dirFunction · 0.68