Re: off_t
On Tue, Dec 30, 2008 at 04:50:17PM +0100, Kurt Roeckx wrote:
> On Tue, Dec 30, 2008 at 04:41:57PM +0100, Kurt Roeckx wrote:
> > On Tue, Dec 30, 2008 at 03:11:59PM +0000, Kai Hendry wrote:
> > >
> > > http.c:730: error: format '%lld' expects type 'long long int', but
> > > argument 8 has type '__off_t'
> >
> > I think it's actually a "long int" (or just long) on amd64, since it's
> > already 64 bit long. I think we have 1 or 2 other arches with
> > the same problem.
> >
> > As far as I know, there is no printf specifier for it, and
> > <inttypes.h> doesn't seem to have anything for it either.
> >
> > So what you should do is make a configure test to check the size
> > and then use something like PRId32 / PRId64.
>
> A configure check probably isn't needed. You can probably just
> use sizeof(off_t) at compile time.
You can't use sizeof() in an #if, the package is not using configure,
so it seems the easiest way is to cast it to an intmax_t and use
%jd. I've attached a patch that does that.
Kurt
diff --git a/src/nhttpd/http.c b/src/nhttpd/http.c
index 571ed8c..d9950a7 100644
--- a/src/nhttpd/http.c
+++ b/src/nhttpd/http.c
@@ -30,6 +30,7 @@
#include <syslog.h>
#include <time.h>
#include <unistd.h>
+#include <stdint.h>
#include "../libmy/str.h"
#include "../libmy/file.h"
@@ -725,9 +726,9 @@ http_proc(const char *header, char *body, const int hr, const int blen,
/* create html file entry */
snprintf(tmp, sizeof(tmp),
"<tr><td>%s</td><td><a href=\"%s\">%s</a>"
- "</td><td>%s</td><td>%lld</td></tr>\n",
+ "</td><td>%s</td><td>%jd</td></tr>\n",
image, dirsort[i], dirsort[i], http_date(t),
- sta.st_size);
+ (intmax_t)sta.st_size);
/* buffer full? send it! */
if (strlen(tmp) > sizeof(buf) - strlen(buf)) {
@@ -1051,9 +1052,9 @@ http_alog(const int sfd, const int hr)
time(&tnow);
t = localtime(&tnow);
- snprintf(log_1, sizeof(log_1), "%s - - %s \"%s\" %d %lld",
+ snprintf(log_1, sizeof(log_1), "%s - - %s \"%s\" %d %jd",
c[sfd].ip, sys_date(t), c[sfd].plreq[hr], c[sfd].psta[hr],
- c[sfd].pfds[hr]);
+ (intmax_t)c[sfd].pfds[hr]);
snprintf(log_2, sizeof(log_2), "\"%s\" \"%s\"",
c[sfd].plref[hr], c[sfd].plagt[hr]);
@@ -1731,14 +1732,16 @@ http_header(const char *header_data, const char *force_status,
/* Last-Modified:, Content-Length: */
if ((h->rp_status == 200 || h->rp_status == 206) && h->x_cgi == 0 &&
h->x_idx == 0) {
- snprintf(tmp, sizeof(tmp), "%s %s\r\n%s %lld\r\n",
- http_fn_lmd, h->rp_fv_dam, http_fn_clt, h->rp_fsize);
+ snprintf(tmp, sizeof(tmp), "%s %s\r\n%s %jd\r\n",
+ http_fn_lmd, h->rp_fv_dam, http_fn_clt,
+ (intmax_t)h->rp_fsize);
strlcat(h->rp_header, tmp, sizeof(h->rp_header));
}
/* Content-Range: */
if (h->rp_status == 206 && h->x_cgi == 0 && h->x_idx == 0) {
- snprintf(tmp, sizeof(tmp), "%s bytes %lld-%lld/%lld\r\n",
- http_fn_rac, h->rp_foffs, fsize - 1, fsize);
+ snprintf(tmp, sizeof(tmp), "%s bytes %jd-%jd/%jd\r\n",
+ http_fn_rac, (intmax_t)h->rp_foffs,
+ (intmax_t)(fsize - 1), (intmax_t)fsize);
strlcat(h->rp_header, tmp, sizeof(h->rp_header));
}
/* Content-Type: */
Reply to: