Skip to content

Commit 83764f8

Browse files
committed
shared/libcrypt-util: include fewer headers
Now that we wrap crypt_r/ra uses, we can include the header only in libcrypt-util.c.
1 parent 999b49c commit 83764f8

File tree

3 files changed

+21
-14
lines changed

3 files changed

+21
-14
lines changed

src/shared/libcrypt-util.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
11
/* SPDX-License-Identifier: LGPL-2.1+ */
22

3+
#if HAVE_CRYPT_H
4+
/* libxcrypt is a replacement for glibc's libcrypt, and libcrypt might be
5+
* removed from glibc at some point. As part of the removal, defines for
6+
* crypt(3) are dropped from unistd.h, and we must include crypt.h instead.
7+
*
8+
* Newer versions of glibc (v2.0+) already ship crypt.h with a definition
9+
* of crypt(3) as well, so we simply include it if it is present. MariaDB,
10+
* MySQL, PostgreSQL, Perl and some other wide-spread packages do it the
11+
* same way since ages without any problems.
12+
*/
13+
# include <crypt.h>
14+
#else
15+
# include <unistd.h>
16+
#endif
17+
318
#include <errno.h>
419
#include <stdlib.h>
520

src/shared/libcrypt-util.h

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,7 @@
11
/* SPDX-License-Identifier: LGPL-2.1+ */
22
#pragma once
33

4-
#if HAVE_CRYPT_H
5-
/* libxcrypt is a replacement for glibc's libcrypt, and libcrypt might be
6-
* removed from glibc at some point. As part of the removal, defines for
7-
* crypt(3) are dropped from unistd.h, and we must include crypt.h instead.
8-
*
9-
* Newer versions of glibc (v2.0+) already ship crypt.h with a definition
10-
* of crypt(3) as well, so we simply include it if it is present. MariaDB,
11-
* MySQL, PostgreSQL, Perl and some other wide-spread packages do it the
12-
* same way since ages without any problems.
13-
*/
14-
#include <crypt.h>
15-
#endif
16-
174
#include <stdbool.h>
18-
#include <stdlib.h>
195

206
int make_salt(char **ret);
217
int hash_password_full(const char *password, void **cd_data, int *cd_size, char **ret);

src/test/test-libcrypt-util.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
/* SPDX-License-Identifier: LGPL-2.1+ */
22

3+
#if HAVE_CRYPT_H
4+
# include <crypt.h>
5+
#else
6+
# include <unistd.h>
7+
#endif
8+
39
#include "strv.h"
410
#include "tests.h"
511
#include "libcrypt-util.h"

0 commit comments

Comments
 (0)