"GOT", but the "O" is a cute, smiling pufferfish. Index | Thread | Search

From:
Christian Weisgerber <naddy@mips.inka.de>
Subject:
Re: inttypes.h?
To:
gameoftrees@openbsd.org
Date:
Sat, 26 Sep 2020 17:41:58 +0200

Download raw body.

Thread
  • Christian Weisgerber:

    inttypes.h?

    • Stefan Sperling:

      inttypes.h?

      • Christian Weisgerber:

        inttypes.h?

Stefan Sperling:

> > What's the attitude here about using POSIX <inttypes.h> and its
> > printf/scanf macros like PRIi64?  Asking for a friend...
> 
> If will help you, then yes, go for it.
> 
> Our use of specific integer widths should be limited to very specific areas
> anyway, such as file format support code.

Yes, on second thought <inttypes.h> doesn't help, because the problem
are our dear old friends time_t and off_t.

The diff below

* ... casts time_t and off_t values to long long, so they are
  guaranteed to match the %lld format specifier.  On OpenBSD that
  happens to be the case, on FreeBSD it's a mess that varies by
  architecture.  I don't know if that's acceptable, but I see similar
  casts in ssh.
  (Style? Second change in got_object_commit_create() below.)

* ... switches the number in parse.y from int64_t to long long,
  since it is assigned to from strtonum(), passed to parseport()'s
  long long parameter, and printed with %lld anyway.


diff 820059fa2d7c7e7a0c9523368dad51044a088bbc /home/naddy/got
blob - 1f7229094154e82356786654751780bbf662dbac
file + got/got.c
--- got/got.c
+++ got/got.c
@@ -9427,11 +9427,11 @@ cat_commit(struct got_object_id *id, struct got_reposi
 	}
 	fprintf(outfile, "%s%s %lld +0000\n", GOT_COMMIT_LABEL_AUTHOR,
 	    got_object_commit_get_author(commit),
-	    got_object_commit_get_author_time(commit));
+	    (long long)got_object_commit_get_author_time(commit));
 
 	fprintf(outfile, "%s%s %lld +0000\n", GOT_COMMIT_LABEL_COMMITTER,
 	    got_object_commit_get_author(commit),
-	    got_object_commit_get_committer_time(commit));
+	    (long long)got_object_commit_get_committer_time(commit));
 
 	logmsg = got_object_commit_get_logmsg_raw(commit);
 	fprintf(outfile, "messagelen %zd\n", strlen(logmsg));
@@ -9486,7 +9486,7 @@ cat_tag(struct got_object_id *id, struct got_repositor
 
 	fprintf(outfile, "%s%s %lld +0000\n", GOT_TAG_LABEL_TAGGER,
 	    got_object_tag_get_tagger(tag),
-	    got_object_tag_get_tagger_time(tag));
+	    (long long)got_object_tag_get_tagger_time(tag));
 
 	tagmsg = got_object_tag_get_message(tag);
 	fprintf(outfile, "messagelen %zd\n", strlen(tagmsg));
blob - 73b108d609463ae2121d561cbfcf7c2bc6924d2b
file + lib/object_create.c
--- lib/object_create.c
+++ lib/object_create.c
@@ -142,7 +142,7 @@ got_object_blob_file_create(struct got_object_id **id,
 	}
 
 	if (asprintf(&header, "%s %lld", GOT_OBJ_LABEL_BLOB,
-		sb.st_size) == -1) {
+		(long long)sb.st_size) == -1) {
 		err = got_error_from_errno("asprintf");
 		goto done;
 	}
@@ -438,12 +438,12 @@ got_object_commit_create(struct got_object_id **id,
 	}
 
 	if (asprintf(&author_str, "%s%s %lld +0000\n",
-	    GOT_COMMIT_LABEL_AUTHOR, author, author_time) == -1)
+	    GOT_COMMIT_LABEL_AUTHOR, author, (long long)author_time) == -1)
 		return got_error_from_errno("asprintf");
 
 	if (asprintf(&committer_str, "%s%s %lld +0000\n",
 	    GOT_COMMIT_LABEL_COMMITTER, committer ? committer : author,
-	    committer ? committer_time : author_time)
+	    (long long)(committer ? committer_time : author_time))
 	    == -1) {
 		err = got_error_from_errno("asprintf");
 		goto done;
@@ -644,7 +644,7 @@ got_object_tag_create(struct got_object_id **id,
 	}
 
 	if (asprintf(&tagger_str, "%s%s %lld +0000\n",
-	    GOT_TAG_LABEL_TAGGER, tagger, tagger_time) == -1)
+	    GOT_TAG_LABEL_TAGGER, tagger, (long long)tagger_time) == -1)
 		return got_error_from_errno("asprintf");
 
 	msg0 = strdup(tagmsg);
blob - 2a929a4ab71f2ead616af3510f5381d8284396b6
file + libexec/got-index-pack/got-index-pack.c
--- libexec/got-index-pack/got-index-pack.c
+++ libexec/got-index-pack/got-index-pack.c
@@ -244,7 +244,8 @@ read_packed_object(struct got_pack *pack, struct got_i
 			free(data);
 			break;
 		}
-		if (asprintf(&header, "%s %lld", obj_label, obj->size) == -1) {
+		if (asprintf(&header, "%s %lld", obj_label,
+		    (long long)obj->size) == -1) {
 			err = got_error_from_errno("asprintf");
 			free(data);
 			break;
blob - 2ae503c4da4198a918f6bbb1bed217eb6bbba8b0
file + libexec/got-read-gotconfig/parse.y
--- libexec/got-read-gotconfig/parse.y
+++ libexec/got-read-gotconfig/parse.y
@@ -84,7 +84,7 @@ static const struct got_error* new_remote(struct gotco
 
 typedef struct {
 	union {
-		int64_t		 number;
+		long long	 number;
 		char		*string;
 		struct node_branch *branch;
 	} v;
-- 
Christian "naddy" Weisgerber                          naddy@mips.inka.de