diff options
Diffstat (limited to 'page.c')
| -rw-r--r-- | page.c | 33 |
1 files changed, 33 insertions, 0 deletions
@@ -2199,3 +2199,36 @@ end: return ret; } + +int page_head_resource(struct http_response *const r, const char *const res) +{ + struct stat sb; + + if (stat(res, &sb)) + { + if (errno == ENOENT || errno == ENOTDIR) + return page_not_found(r); + else + { + fprintf(stderr, "%s: stat(2) %s: %s\n", + __func__, res, strerror(errno)); + return -1; + } + } + + const mode_t m = sb.st_mode; + + if (!S_ISDIR(m) && !S_ISREG(m)) + { + fprintf(stderr, "%s: unexpected st_mode %jd\n", __func__, (intmax_t)m); + return -1; + } + + *r = (const struct http_response) + { + .status = HTTP_STATUS_OK, + .n = sb.st_size + }; + + return 0; +} |
