Skip to contentSkip to conversation

man3: SYNOPSIS: Use 'restrict' in prototypes (batch 2)

PATCH In review Alejandro Colomar 2 participants 16 messages Feb 28, 2021 – Mar 4, 2021 Man-pages: manual pages for Linux -- Sections 2, 3, 4, 5, and 7

lore
Share & tools
lore
#0 lore raw

cover man3: SYNOPSIS: Use 'restrict' in prototypes (batch 2)

Hey Michael,

This is the second batch of pages in man3 that use 'restrict'.

I have already checked until getrpcport.3.

---

A few functions to automate the commit messages:

For functions that are restrict in POSIX and glibc:

function gitcommit_rp()

{
	local commafuncs="$(echo $@ |sed -e 's/\> \</(), /g' -e 's/$/()/')";
	local msg="\

$(man_gitstaged): SYNOPSIS: Use 'restrict' in prototypes

Both POSIX and glibc use 'restrict' in ${commafuncs}. Let's use it here too.

$(echo "$@" \

  |xargs -n1 bash -c \
    'echo ".../glibc$ grep_glibc_prototype $@"; \
     echo "$(cd ~/src/gnu/glibc && grep_glibc_prototype $@)"' _)

.../glibc$";

	git commit -sm "$msg";
}

For functions that are restrict in glibc:

function gitcommit_rg()

{
	local commafuncs="$(echo $@ |sed -e 's/\> \</(), /g' -e 's/$/()/')";
	local msg="\

$(man_gitstaged): SYNOPSIS: Use 'restrict' in prototypes

glibc uses 'restrict' in ${commafuncs}.
Let's use it here too.

$(echo "$@" \

  |xargs -n1 bash -c \
    'echo ".../glibc$ grep_glibc_prototype $@"; \
     echo "$(cd ~/src/gnu/glibc && grep_glibc_prototype $@)"' _)

.../glibc$";

	git commit -sm "$msg";
}

---
Alejandro Colomar (14):
getaddrinfo.3: SYNOPSIS: Use 'restrict' in prototypes getaddrinfo_a.3: SYNOPSIS: Use 'restrict' in prototypes getdate.3: SYNOPSIS: Use 'restrict' in prototypes getdirentries.3: SYNOPSIS: Use 'restrict' in prototypes getgrent_r.3: SYNOPSIS: Use 'restrict' in prototypes getgrnam.3: SYNOPSIS: Use 'restrict' in prototypes gethostbyname.3: SYNOPSIS: Use 'restrict' in prototypes getline.3: SYNOPSIS: Use 'restrict' in prototypes getmntent.3: SYNOPSIS: Use 'restrict' in prototypes getnameinfo.3: SYNOPSIS: Use 'restrict' in prototypes getnetent_r.3: SYNOPSIS: Use 'restrict' in prototypes getprotoent_r.3: SYNOPSIS: Use 'restrict' in prototypes getpwent_r.3: SYNOPSIS: Use 'restrict' in prototypes getpwnam.3: SYNOPSIS: Use 'restrict' in prototypes

 man3/getaddrinfo.3   | 11 ++++++-----
 man3/getaddrinfo_a.3 | 12 ++++++------
 man3/getdate.3       |  2 +-
 man3/getdirentries.3 |  4 ++--
 man3/getgrent_r.3    | 10 ++++++----
 man3/getgrnam.3      | 11 +++++++----
 man3/gethostbyname.3 | 31 ++++++++++++++++++++-----------
 man3/getline.3       |  7 ++++---
 man3/getmntent.3     |  8 +++++---
 man3/getnameinfo.3   |  8 +++++---
 man3/getnetent_r.3   | 23 +++++++++++++----------
 man3/getprotoent_r.3 | 17 ++++++++++-------
 man3/getpwent_r.3    | 11 +++++++----
 man3/getpwnam.3      | 11 +++++++----
 14 files changed, 99 insertions(+), 67 deletions(-)
Signature · 1 line
2.30.1.721.g45526154a5
#1 lore raw

PATCH 1/14 getaddrinfo.3: SYNOPSIS: Use 'restrict' in prototypes

Both POSIX and glibc use 'restrict' in getaddrinfo(). Let's use it here too.

.../glibc$ grep_glibc_prototype getaddrinfo; resolv/netdb.h:660:
extern int getaddrinfo (const char *__restrict __name,
const char *__restrict __service, const struct addrinfo *__restrict __req, struct addrinfo **__restrict __pai);
.../glibc$

---
 man3/getaddrinfo.3 | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)
man3/getaddrinfo.3 +6 -5
index db397bdf8..37710c277 100644
@@ -51,13 +51,14 @@ service translation
 .B #include <sys/socket.h>
 .B #include <netdb.h>
 .PP
-.BI "int getaddrinfo(const char *" "node" ", const char *" "service" ,
-.BI "                const struct addrinfo *" "hints" ,
-.BI "                struct addrinfo **" "res" );
+.BI "int getaddrinfo(const char *restrict " node ,
+.BI "                const char *restrict " service ,
+.BI "                const struct addrinfo *restrict " hints ,
+.BI "                struct addrinfo **restrict " res );
 .PP
-.BI "void freeaddrinfo(struct addrinfo *" "res" );
+.BI "void freeaddrinfo(struct addrinfo *" res );
 .PP
-.BI "const char *gai_strerror(int " "errcode" );
+.BI "const char *gai_strerror(int " errcode );
 .fi
 .PP
 .RS -4
Signature · 1 line
2.30.1.721.g45526154a5
#2 lore raw

PATCH 2/14 getaddrinfo_a.3: SYNOPSIS: Use 'restrict' in prototypes

In reply to Alejandro Colomar

glibc uses 'restrict' in getaddrinfo_a().
Let's use it here too.

.../glibc$ grep_glibc_prototype getaddrinfo_a resolv/netdb.h:690:
extern int getaddrinfo_a (int __mode, struct gaicb *__list[__restrict_arr],

			  int __ent, struct sigevent *__restrict __sig);

.../glibc$

---
 man3/getaddrinfo_a.3 | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
man3/getaddrinfo_a.3 +6 -6
index 416904437..0ddb8a76d 100644
@@ -36,13 +36,13 @@ network address and service translation
 .BR "#define _GNU_SOURCE" "         /* See feature_test_macros(7) */"
 .B #include <netdb.h>
 .PP
-.BI "int getaddrinfo_a(int " "mode" ", struct gaicb *" "list[]" ,
-.BI "                  int " "nitems" ", struct sigevent *" "sevp" );
-.BI "int gai_suspend(const struct gaicb * const " "list[]" ", int " "nitems" ,
-.BI "                  const struct timespec *" "timeout" );
+.BI "int getaddrinfo_a(int " mode ", struct gaicb *" list [restrict],
+.BI "                  int " nitems ", struct sigevent *restrict " sevp );
+.BI "int gai_suspend(const struct gaicb *const " list "[], int " nitems ,
+.BI "                  const struct timespec *" timeout );
 .PP
-.BI "int gai_error(struct gaicb *" "req" );
-.BI "int gai_cancel(struct gaicb *" "req" );
+.BI "int gai_error(struct gaicb *" req );
+.BI "int gai_cancel(struct gaicb *" req );
 .PP
 Link with \fI\-lanl\fP.
 .fi
Signature · 1 line
2.30.1.721.g45526154a5
#3 lore raw

PATCH 3/14 getdate.3: SYNOPSIS: Use 'restrict' in prototypes

In reply to Alejandro Colomar

glibc uses 'restrict' in getdate_r().
Let's use it here too.

.../glibc$ grep_glibc_prototype getdate_r time/time.h:297:
extern int getdate_r (const char *__restrict __string,

		      struct tm *__restrict __resbufp);

.../glibc$

---
 man3/getdate.3 | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
man3/getdate.3 +1 -1
index 1f8432303..5334b4bb6 100644
@@ -40,7 +40,7 @@ getdate, getdate_r \- convert a date-plus-time string to broken-down time
 .PP
 .B "#include <time.h>"
 .PP
-.BI "int getdate_r(const char *" string ", struct tm *" res );
+.BI "int getdate_r(const char *restrict " string ", struct tm *restrict " res );
 .fi
 .PP
 .RS -4
Signature · 1 line
2.30.1.721.g45526154a5
#4 lore raw

PATCH 4/14 getdirentries.3: SYNOPSIS: Use 'restrict' in prototypes

In reply to Alejandro Colomar

glibc uses 'restrict' in getdirentries().
Let's use it here too.

.../glibc$ grep_glibc_prototype getdirentries dirent/dirent.h:353:
extern __ssize_t getdirentries (int __fd, char *__restrict __buf,

				size_t __nbytes,
				__off_t *__restrict __basep)
     __THROW __nonnull ((2, 4));

.../glibc$

---
 man3/getdirentries.3 | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
man3/getdirentries.3 +2 -2
index 0deff6371..9bba3cc4b 100644
@@ -31,8 +31,8 @@ getdirentries \- get directory entries in a filesystem-independent format
 .nf
 .B #include <dirent.h>
 .PP
-.BI "ssize_t getdirentries(int " fd ", char *" buf ", size_t " nbytes ,
-.BI "                      off_t *" basep );
+.BI "ssize_t getdirentries(int " fd ", char *restrict " buf ", size_t " nbytes ,
+.BI "                      off_t *restrict " basep );
 .fi
 .PP
 .RS -4
Signature · 1 line
2.30.1.721.g45526154a5
#5 lore raw

PATCH 5/14 getgrent_r.3: SYNOPSIS: Use 'restrict' in prototypes

In reply to Alejandro Colomar

glibc uses 'restrict' in getgrent_r(), fgetgrent_r(). Let's use it here too.

.../glibc$ grep_glibc_prototype getgrent_r grp/grp.h:131:
extern int getgrent_r (struct group *__restrict __resultbuf,

		       char *__restrict __buffer, size_t __buflen,
		       struct group **__restrict __result);

.../glibc$ grep_glibc_prototype fgetgrent_r grp/grp.h:161:
extern int fgetgrent_r (FILE *__restrict __stream,
struct group *__restrict __resultbuf, char *__restrict __buffer, size_t __buflen, struct group **__restrict __result);
.../glibc$

---
 man3/getgrent_r.3 | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
man3/getgrent_r.3 +6 -4
index 55d9d698f..29f063a0a 100644
@@ -28,10 +28,12 @@ getgrent_r, fgetgrent_r \- get group file entry reentrantly
 .nf
 .B #include <grp.h>
 .PP
-.BI "int getgrent_r(struct group *" gbuf ", char *" buf ,
-.BI "               size_t " buflen ", struct group **" gbufp );
-.BI "int fgetgrent_r(FILE *" stream ", struct group *" gbuf ", char *" buf ,
-.BI "               size_t " buflen ", struct group **" gbufp );
+.BI "int getgrent_r(struct group *restrict " gbuf ,
+.BI "               char *restrict " buf ", size_t " buflen ,
+.BI "               struct group **restrict " gbufp );
+.BI "int fgetgrent_r(FILE *restrict " stream ", struct group *restrict " gbuf ,
+.BI "               char *restrict " buf ", size_t " buflen ,
+.BI "               struct group **restrict " gbufp );
 .fi
 .PP
 .RS -4
Signature · 1 line
2.30.1.721.g45526154a5
#6 lore raw

PATCH 6/14 getgrnam.3: SYNOPSIS: Use 'restrict' in prototypes

In reply to Alejandro Colomar

POSIX does NOT specify these functions to use 'restrict'. However, glibc uses 'restrict' in getgrnam_r(), getgrgid_r(). Users might be surprised by this! Let's use it here too!

.../glibc$ grep_glibc_prototype getgrnam_r
grp/grp.h:148:
extern int getgrnam_r (const char *__restrict __name,
struct group *__restrict __resultbuf, char *__restrict __buffer, size_t __buflen, struct group **__restrict __result);
.../glibc$ grep_glibc_prototype getgrgid_r
grp/grp.h:140:
extern int getgrgid_r (__gid_t __gid, struct group *__restrict __resultbuf,

		       char *__restrict __buffer, size_t __buflen,
		       struct group **__restrict __result);

.../glibc$

---
 man3/getgrnam.3 | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
man3/getgrnam.3 +7 -4
index 87f61c260..1b13208ba 100644
@@ -41,10 +41,13 @@ getgrnam, getgrnam_r, getgrgid, getgrgid_r \- get group file entry
 .BI "struct group *getgrnam(const char *" name );
 .BI "struct group *getgrgid(gid_t " gid );
 .PP
-.BI "int getgrnam_r(const char *" name ", struct group *" grp ,
-.BI "          char *" buf ", size_t " buflen ", struct group **" result );
-.BI "int getgrgid_r(gid_t " gid ", struct group *" grp ,
-.BI "          char *" buf ", size_t " buflen ", struct group **" result );
+.BI "int getgrnam_r(const char *restrict " name \
+", struct group *restrict " grp ,
+.BI "               char *restrict " buf ", size_t " buflen ,
+.BI "               struct group **restrict " result );
+.BI "int getgrgid_r(gid_t " gid ", struct group *restrict " grp ,
+.BI "               char *restrict " buf ", size_t " buflen ,
+.BI "               struct group **restrict " result );
 .fi
 .PP
 .RS -4
Signature · 1 line
2.30.1.721.g45526154a5
#7 lore raw

PATCH 7/14 gethostbyname.3: SYNOPSIS: Use 'restrict' in prototypes

In reply to Alejandro Colomar

glibc uses 'restrict' in gethostent_r(), gethostbyaddr_r(), gethostbyname_r(), gethostbyname2_r().
Let's use it here too.

.../glibc$ grep_glibc_prototype gethostent_r
resolv/netdb.h:165:
extern int gethostent_r (struct hostent *__restrict __result_buf,
char *__restrict __buf, size_t __buflen, struct hostent **__restrict __result, int *__restrict __h_errnop);
.../glibc$ grep_glibc_prototype gethostbyaddr_r resolv/netdb.h:170:
extern int gethostbyaddr_r (const void *__restrict __addr, __socklen_t __len,
int __type,
struct hostent *__restrict __result_buf, char *__restrict __buf, size_t __buflen, struct hostent **__restrict __result, int *__restrict __h_errnop);
.../glibc$ grep_glibc_prototype gethostbyname_r resolv/netdb.h:177:
extern int gethostbyname_r (const char *__restrict __name,
struct hostent *__restrict __result_buf, char *__restrict __buf, size_t __buflen, struct hostent **__restrict __result, int *__restrict __h_errnop);
.../glibc$ grep_glibc_prototype gethostbyname2_r resolv/netdb.h:183:
extern int gethostbyname2_r (const char *__restrict __name, int __af,
struct hostent *__restrict __result_buf, char *__restrict __buf, size_t __buflen, struct hostent **__restrict __result, int *__restrict __h_errnop);
.../glibc$

---
 man3/gethostbyname.3 | 31 ++++++++++++++++++++-----------
 1 file changed, 20 insertions(+), 11 deletions(-)
man3/gethostbyname.3 +20 -11
index ac1758ca0..d2c456072 100644
@@ -65,18 +65,27 @@ gethostent_r \- get network host entry
 /* GNU extensions */
 .BI "struct hostent *gethostbyname2(const char *" name ", int " af );
 .PP
-.BI "int gethostent_r(struct hostent *" ret ", char *" buf ", size_t " buflen ,
-.BI "                 struct hostent **" result ", int *" h_errnop );
+.BI "int gethostent_r(struct hostent *restrict " ret ,
+.BI "                 char *restrict " buf ", size_t " buflen ,
+.BI "                 struct hostent **restrict " result ,
+.BI "                 int *restrict " h_errnop );
 .PP
-.BI "int gethostbyaddr_r(const void *" addr ", socklen_t " len ", int " type ,
-.BI "                 struct hostent *" ret ", char *" buf ", size_t " buflen ,
-.BI "                 struct hostent **" result ", int *" h_errnop );
-.BI "int gethostbyname_r(const char *" name ,
-.BI "                 struct hostent *" ret ", char *" buf ", size_t " buflen ,
-.BI "                 struct hostent **" result ", int *" h_errnop );
-.BI "int gethostbyname2_r(const char *" name ", int " af,
-.BI "                 struct hostent *" ret ", char *" buf ", size_t " buflen ,
-.BI "                 struct hostent **" result ", int *" h_errnop );
+.BI "int gethostbyaddr_r(const void *restrict " addr ", socklen_t " len \
+", int " type ,
+.BI "                 struct hostent *restrict " ret ,
+.BI "                 char *restrict " buf ", size_t " buflen ,
+.BI "                 struct hostent **restrict " result ,
+.BI "                 int *restrict " h_errnop );
+.BI "int gethostbyname_r(const char *restrict " name ,
+.BI "                 struct hostent *restrict " ret ,
+.BI "                 char *restrict " buf ", size_t " buflen ,
+.BI "                 struct hostent **restrict " result ,
+.BI "                 int *restrict " h_errnop );
+.BI "int gethostbyname2_r(const char *restrict " name ", int " af,
+.BI "                 struct hostent *restrict " ret ,
+.BI "                 char *restrict " buf ", size_t " buflen ,
+.BI "                 struct hostent **restrict " result ,
+.BI "                 int *restrict " h_errnop );
 .fi
 .PP
 .RS -4
Signature · 1 line
2.30.1.721.g45526154a5
#8 lore raw

PATCH 8/14 getline.3: SYNOPSIS: Use 'restrict' in prototypes

In reply to Alejandro Colomar

Both POSIX and glibc use 'restrict' in getline(), getdelim(). Let's use it here too.

.../glibc$ grep_glibc_prototype getline libio/stdio.h:621:
extern __ssize_t getline (char **__restrict __lineptr,

                          size_t *__restrict __n,
                          FILE *__restrict __stream) __wur;

.../glibc$ grep_glibc_prototype getdelim libio/stdio.h:611:
extern __ssize_t getdelim (char **__restrict __lineptr,
size_t *__restrict __n, int __delimiter, FILE *__restrict __stream) __wur;
.../glibc$

---
 man3/getline.3 | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
man3/getline.3 +4 -3
index 25930dbf9..182a8ca85 100644
@@ -30,9 +30,10 @@ getline, getdelim \- delimited string input
 .nf
 .B #include <stdio.h>
 .PP
-.BI "ssize_t getline(char **" lineptr ", size_t *" n ", FILE *" stream );
-.BI "ssize_t getdelim(char **" lineptr ", size_t *" n ", int " delim \
-", FILE *" stream );
+.BI "ssize_t getline(char **restrict " lineptr ", size_t *restrict " n ,
+.BI "                FILE *restrict " stream );
+.BI "ssize_t getdelim(char **restrict " lineptr ", size_t *restrict " n ,
+.BI "                int " delim ", FILE *restrict " stream );
 .fi
 .PP
 .RS -4
Signature · 1 line
2.30.1.721.g45526154a5
#9 lore raw

PATCH 9/14 getmntent.3: SYNOPSIS: Use 'restrict' in prototypes

In reply to Alejandro Colomar

glibc uses 'restrict' in addmntent(), getmntent_r(). Let's use it here too.

.../glibc$ grep_glibc_prototype addmntent
misc/mntent.h:81:
extern int addmntent (FILE *__restrict __stream,

		      const struct mntent *__restrict __mnt) __THROW;

.../glibc$ grep_glibc_prototype getmntent_r misc/mntent.h:73:
extern struct mntent *getmntent_r (FILE *__restrict __stream,
struct mntent *__restrict __result, char *__restrict __buffer, int __bufsize) __THROW;
.../glibc$

---
 man3/getmntent.3 | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
man3/getmntent.3 +5 -3
index 7f83ed248..96e642d18 100644
@@ -42,7 +42,8 @@ getmntent_r \- get filesystem descriptor file entry
 .PP
 .BI "struct mntent *getmntent(FILE *" stream );
 .PP
-.BI "int addmntent(FILE *" stream ", const struct mntent *" mnt );
+.BI "int addmntent(FILE *restrict " stream ,
+.BI "              const struct mntent *restrict " mnt );
 .PP
 .BI "int endmntent(FILE *" streamp );
 .PP
@@ -51,8 +52,9 @@ getmntent_r \- get filesystem descriptor file entry
 /* GNU extension */
 .B #include <mntent.h>
 .PP
-.BI "struct mntent *getmntent_r(FILE *" streamp ", struct mntent *" mntbuf ,
-.BI "                           char *" buf ", int " buflen );
+.BI "struct mntent *getmntent_r(FILE *restrict " streamp ,
+.BI "              struct mntent *restrict " mntbuf ,
+.BI "              char *restrict " buf ", int " buflen );
 .fi
 .PP
 .RS -4
Signature · 1 line
2.30.1.721.g45526154a5
#10 lore raw

PATCH 10/14 getnameinfo.3: SYNOPSIS: Use 'restrict' in prototypes

In reply to Alejandro Colomar

Both POSIX and glibc use 'restrict' in getnameinfo(). Let's use it here too.

I conciously did an exception with respect to the right margin of the rendered page. Instead of having the right margin at 78 as usual (per Branden's recommendation), I let it use col 79 this time, to avoid breaking the prototype in an ugly way.

.../glibc$ grep_glibc_prototype getnameinfo resolv/netdb.h:675:
extern int getnameinfo (const struct sockaddr *__restrict __sa,
socklen_t __salen, char *__restrict __host, socklen_t __hostlen, char *__restrict __serv, socklen_t __servlen, int __flags);
.../glibc$

Cc G. Branden Robinson <[email protected]>
---
 man3/getnameinfo.3 | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
man3/getnameinfo.3 +5 -3
index eff8b2562..d4d3f42e5 100644
@@ -15,9 +15,11 @@ getnameinfo \- address-to-name translation in protocol-independent manner
 .B #include <sys/socket.h>
 .B #include <netdb.h>
 .PP
-.BI "int getnameinfo(const struct sockaddr *" "addr" ", socklen_t " "addrlen" ,
-.BI "                char *" "host" ", socklen_t " "hostlen" ,
-.BI "                char *" "serv" ", socklen_t " "servlen" ", int " "flags" );
+.BI "int getnameinfo(const struct sockaddr *restrict " addr \
+", socklen_t " addrlen ,
+.BI "                char *restrict " host ", socklen_t " hostlen ,
+.BI "                char *restrict " serv ", socklen_t " servlen \
+", int " flags );
 .fi
 .PP
 .RS -4
Signature · 1 line
2.30.1.721.g45526154a5
#11 lore raw

PATCH 11/14 getnetent_r.3: SYNOPSIS: Use 'restrict' in prototypes

In reply to Alejandro Colomar

glibc uses 'restrict' in getnetent_r(), getnetbyname_r(), getnetbyaddr_r().
Let's use it here too.

.../glibc$ grep_glibc_prototype getnetent_r resolv/netdb.h:235:
extern int getnetent_r (struct netent *__restrict __result_buf,
char *__restrict __buf, size_t __buflen, struct netent **__restrict __result, int *__restrict __h_errnop);
.../glibc$ grep_glibc_prototype getnetbyname_r resolv/netdb.h:246:
extern int getnetbyname_r (const char *__restrict __name,
struct netent *__restrict __result_buf, char *__restrict __buf, size_t __buflen, struct netent **__restrict __result, int *__restrict __h_errnop);
.../glibc$ grep_glibc_prototype getnetbyaddr_r resolv/netdb.h:240:
extern int getnetbyaddr_r (uint32_t __net, int __type,
struct netent *__restrict __result_buf, char *__restrict __buf, size_t __buflen, struct netent **__restrict __result, int *__restrict __h_errnop);
.../glibc$

---
 man3/getnetent_r.3 | 23 +++++++++++++----------
 1 file changed, 13 insertions(+), 10 deletions(-)
man3/getnetent_r.3 +13 -10
index 679391cd0..b94a67ba5 100644
@@ -31,17 +31,20 @@ network entry (reentrant)
 .nf
 .B #include <netdb.h>
 .PP
-.BI "int getnetent_r(struct netent *" result_buf ", char *" buf ,
-.BI "                size_t " buflen ", struct netent **" result ,
-.BI "                int *" h_errnop );
-.BI "int getnetbyname_r(const char *" name ,
-.BI "                struct netent *" result_buf ", char *" buf ,
-.BI "                size_t " buflen ", struct netent **" result ,
-.BI "                int *" h_errnop );
+.BI "int getnetent_r(struct netent *restrict " result_buf ,
+.BI "                char *restrict " buf ", size_t " buflen ,
+.BI "                struct netent **restrict " result ,
+.BI "                int *restrict " h_errnop );
+.BI "int getnetbyname_r(const char *restrict " name ,
+.BI "                struct netent *restrict " result_buf ,
+.BI "                char *restrict " buf ", size_t " buflen ,
+.BI "                struct netent **restrict " result ,
+.BI "                int *restrict " h_errnop );
 .BI "int getnetbyaddr_r(uint32_t " net ", int " type ,
-.BI "                struct netent *" result_buf ", char *" buf ,
-.BI "                size_t " buflen ", struct netent **" result ,
-.BI "                int *" h_errnop );
+.BI "                struct netent *restrict " result_buf ,
+.BI "                char *restrict " buf ", size_t " buflen ,
+.BI "                struct netent **restrict " result ,
+.BI "                int *restrict " h_errnop );
 .PP
 .fi
 .RS -4
Signature · 1 line
2.30.1.721.g45526154a5
#12 lore raw

PATCH 12/14 getprotoent_r.3: SYNOPSIS: Use 'restrict' in prototypes

In reply to Alejandro Colomar

glibc uses 'restrict' in getprotoent_r(), getprotobyname_r(), getprotobynumber_r().
Let's use it here too.

.../glibc$ grep_glibc_prototype getprotoent_r resolv/netdb.h:372:
extern int getprotoent_r (struct protoent *__restrict __result_buf,

			  char *__restrict __buf, size_t __buflen,
			  struct protoent **__restrict __result);

.../glibc$ grep_glibc_prototype getprotobyname_r resolv/netdb.h:376:
extern int getprotobyname_r (const char *__restrict __name,
struct protoent *__restrict __result_buf, char *__restrict __buf, size_t __buflen, struct protoent **__restrict __result);
.../glibc$ grep_glibc_prototype getprotobynumber_r resolv/netdb.h:381:
extern int getprotobynumber_r (int __proto,
struct protoent *__restrict __result_buf, char *__restrict __buf, size_t __buflen, struct protoent **__restrict __result);
.../glibc$

---
 man3/getprotoent_r.3 | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)
man3/getprotoent_r.3 +10 -7
index 55e37d0c9..651ec00c2 100644
@@ -31,14 +31,17 @@ protocol entry (reentrant)
 .nf
 .B #include <netdb.h>
 .PP
-.BI "int getprotoent_r(struct protoent *" result_buf ", char *" buf ,
-.BI "                size_t " buflen ", struct protoent **" result );
-.BI "int getprotobyname_r(const char *" name ,
-.BI "                struct protoent *" result_buf ", char *" buf ,
-.BI "                size_t " buflen ", struct protoent **" result );
+.BI "int getprotoent_r(struct protoent *restrict " result_buf ,
+.BI "                  char *restrict " buf ", size_t " buflen ,
+.BI "                  struct protoent **restrict " result );
+.BI "int getprotobyname_r(const char *restrict " name ,
+.BI "                  struct protoent *restrict " result_buf ,
+.BI "                  char *restrict " buf ", size_t " buflen ,
+.BI "                  struct protoent **restrict " result );
 .BI "int getprotobynumber_r(int " proto ,
-.BI "                struct protoent *" result_buf ", char *" buf ,
-.BI "                size_t " buflen ", struct protoent **" result );
+.BI "                  struct protoent *restrict " result_buf ,
+.BI "                  char *restrict " buf ", size_t " buflen ,
+.BI "                  struct protoent **restrict " result );
 .PP
 .fi
 .RS -4
Signature · 1 line
2.30.1.721.g45526154a5
#13 lore raw

PATCH 13/14 getpwent_r.3: SYNOPSIS: Use 'restrict' in prototypes

In reply to Alejandro Colomar

glibc uses 'restrict' in getpwent_r(), fgetpwent_r(). Let's use it here too.

.../glibc$ grep_glibc_prototype getpwent_r pwd/pwd.h:139:
extern int getpwent_r (struct passwd *__restrict __resultbuf,
char *__restrict __buffer, size_t __buflen, struct passwd **__restrict __result) __nonnull ((1, 2, 4));
.../glibc$ grep_glibc_prototype fgetpwent_r pwd/pwd.h:166:
extern int fgetpwent_r (FILE *__restrict __stream,
struct passwd *__restrict __resultbuf, char *__restrict __buffer, size_t __buflen, struct passwd **__restrict __result) __nonnull ((1, 2, 3, 5));
.../glibc$

---
 man3/getpwent_r.3 | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
man3/getpwent_r.3 +7 -4
index 3414b31a8..b2c7e420a 100644
@@ -28,10 +28,13 @@ getpwent_r, fgetpwent_r \- get passwd file entry reentrantly
 .nf
 .B #include <pwd.h>
 .PP
-.BI "int getpwent_r(struct passwd *" pwbuf ", char *" buf ,
-.BI "               size_t " buflen ", struct passwd **" pwbufp );
-.BI "int fgetpwent_r(FILE *" stream ", struct passwd *" pwbuf ", char *" buf ,
-.BI "                size_t " buflen ", struct passwd **" pwbufp );
+.BI "int getpwent_r(struct passwd *restrict " pwbuf ,
+.BI "               char *restrict " buf ", size_t " buflen ,
+.BI "               struct passwd **restrict " pwbufp );
+.BI "int fgetpwent_r(FILE *restrict " stream \
+", struct passwd *restrict " pwbuf ,
+.BI "               char *restrict " buf ", size_t " buflen ,
+.BI "               struct passwd **restrict " pwbufp );
 .fi
 .PP
 .RS -4
Signature · 1 line
2.30.1.721.g45526154a5
#14 lore raw

PATCH 14/14 getpwnam.3: SYNOPSIS: Use 'restrict' in prototypes

In reply to Alejandro Colomar

POSIX does NOT specify these functions to use 'restrict'. However, glibc uses 'restrict' in getpwnam_r(), getpwuid_r(). Let's use it here too.

.../glibc$ grep_glibc_prototype getpwnam_r pwd/pwd.h:151:
extern int getpwnam_r (const char *__restrict __name,
struct passwd *__restrict __resultbuf, char *__restrict __buffer, size_t __buflen, struct passwd **__restrict __result) __nonnull ((1, 2, 3, 5));
.../glibc$ grep_glibc_prototype getpwuid_r pwd/pwd.h:145:
extern int getpwuid_r (__uid_t __uid,
struct passwd *__restrict __resultbuf, char *__restrict __buffer, size_t __buflen, struct passwd **__restrict __result) __nonnull ((2, 3, 5));
.../glibc$

---
 man3/getpwnam.3 | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
man3/getpwnam.3 +7 -4
index 45fde871d..1eed77c45 100644
@@ -45,10 +45,13 @@ getpwnam, getpwnam_r, getpwuid, getpwuid_r \- get password file entry
 .BI "struct passwd *getpwnam(const char *" name );
 .BI "struct passwd *getpwuid(uid_t " uid );
 .PP
-.BI "int getpwnam_r(const char *" name ", struct passwd *" pwd ,
-.BI "               char *" buf ", size_t " buflen ", struct passwd **" result );
-.BI "int getpwuid_r(uid_t " uid ", struct passwd *" pwd ,
-.BI "               char *" buf ", size_t " buflen ", struct passwd **" result );
+.BI "int getpwnam_r(const char *restrict " name \
+", struct passwd *restrict " pwd ,
+.BI "               char *restrict " buf ", size_t " buflen ,
+.BI "               struct passwd **restrict " result );
+.BI "int getpwuid_r(uid_t " uid ", struct passwd *restrict " pwd ,
+.BI "               char *restrict " buf ", size_t " buflen ,
+.BI "               struct passwd **restrict " result );
 .fi
 .PP
 .RS -4
Signature · 1 line
2.30.1.721.g45526154a5
#15 lore raw
In reply to Alejandro Colomar

Hi Alex,

Quoted 5 lines · Alejandro Colomar

Hey Michael,

This is the second batch of pages in man3 that use 'restrict'.

I have already checked until getrpcport.3.

Thanks for doing all of this work!

I've applied all of these patches.

Cheers,

Michael

Quoted 78 lines

---

A few functions to automate the commit messages:

For functions that are restrict in POSIX and glibc:

function gitcommit_rp()

{
	local commafuncs="$(echo $@ |sed -e 's/\> \</(), /g' -e 's/$/()/')";
	local msg="\

$(man_gitstaged): SYNOPSIS: Use 'restrict' in prototypes

Both POSIX and glibc use 'restrict' in ${commafuncs}. Let's use it here too.

$(echo "$@" \

  |xargs -n1 bash -c \
    'echo ".../glibc$ grep_glibc_prototype $@"; \
     echo "$(cd ~/src/gnu/glibc && grep_glibc_prototype $@)"' _)

.../glibc$";

	git commit -sm "$msg";
}

For functions that are restrict in glibc:

function gitcommit_rg()

{
	local commafuncs="$(echo $@ |sed -e 's/\> \</(), /g' -e 's/$/()/')";
	local msg="\

$(man_gitstaged): SYNOPSIS: Use 'restrict' in prototypes

glibc uses 'restrict' in ${commafuncs}.
Let's use it here too.

$(echo "$@" \

  |xargs -n1 bash -c \
    'echo ".../glibc$ grep_glibc_prototype $@"; \
     echo "$(cd ~/src/gnu/glibc && grep_glibc_prototype $@)"' _)

.../glibc$";

	git commit -sm "$msg";
}

---
Alejandro Colomar (14):
getaddrinfo.3: SYNOPSIS: Use 'restrict' in prototypes getaddrinfo_a.3: SYNOPSIS: Use 'restrict' in prototypes getdate.3: SYNOPSIS: Use 'restrict' in prototypes getdirentries.3: SYNOPSIS: Use 'restrict' in prototypes getgrent_r.3: SYNOPSIS: Use 'restrict' in prototypes getgrnam.3: SYNOPSIS: Use 'restrict' in prototypes gethostbyname.3: SYNOPSIS: Use 'restrict' in prototypes getline.3: SYNOPSIS: Use 'restrict' in prototypes getmntent.3: SYNOPSIS: Use 'restrict' in prototypes getnameinfo.3: SYNOPSIS: Use 'restrict' in prototypes getnetent_r.3: SYNOPSIS: Use 'restrict' in prototypes getprotoent_r.3: SYNOPSIS: Use 'restrict' in prototypes getpwent_r.3: SYNOPSIS: Use 'restrict' in prototypes getpwnam.3: SYNOPSIS: Use 'restrict' in prototypes

 man3/getaddrinfo.3   | 11 ++++++-----
 man3/getaddrinfo_a.3 | 12 ++++++------
 man3/getdate.3       |  2 +-
 man3/getdirentries.3 |  4 ++--
 man3/getgrent_r.3    | 10 ++++++----
 man3/getgrnam.3      | 11 +++++++----
 man3/gethostbyname.3 | 31 ++++++++++++++++++++-----------
 man3/getline.3       |  7 ++++---
 man3/getmntent.3     |  8 +++++---
 man3/getnameinfo.3   |  8 +++++---
 man3/getnetent_r.3   | 23 +++++++++++++----------
 man3/getprotoent_r.3 | 17 ++++++++++-------
 man3/getpwent_r.3    | 11 +++++++----
 man3/getpwnam.3      | 11 +++++++----
 14 files changed, 99 insertions(+), 67 deletions(-)
Signature · 3 lines
Michael Kerrisk
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
Linux/UNIX System Programming Training: http://man7.org/training/