| 584 | */ |
| 585 | |
| 586 | mime_type_t * /* O - Type of file */ |
| 587 | mimeFileType(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 | */ |