Skip to content

Commit f0fd5e2

Browse files
authored
Merge pull request #3 from thesamesam/musl
Use <stdint.h> to fix musl compatibility
2 parents 9b26d1c + b7c961d commit f0fd5e2

File tree

4 files changed

+25
-20
lines changed

4 files changed

+25
-20
lines changed

src/ntp.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
#include <netdb.h>
5353
#include <stdio.h>
5454
#include <stdlib.h>
55+
#include <stdint.h>
5556
#include <string.h>
5657
#include <time.h>
5758
#include <unistd.h>
@@ -106,11 +107,11 @@ struct ntp_data {
106107
double receive;
107108
double transmit;
108109
double current;
109-
u_int64_t recvck;
110+
uint64_t recvck;
110111

111112
/* Local State */
112113
double originate;
113-
u_int64_t xmitck;
114+
uint64_t xmitck;
114115
};
115116

116117
void ntp_client(const char *, int, struct timeval *, struct timeval *, int, int, int);
@@ -282,7 +283,7 @@ write_packet(int fd, struct ntp_data *data)
282283

283284
packet[0] = (NTP_VERSION << 3) | (NTP_MODE_CLIENT);
284285

285-
data->xmitck = (u_int64_t)arc4random() << 32 | arc4random();
286+
data->xmitck = (uint64_t)arc4random() << 32 | arc4random();
286287

287288
/*
288289
* Send out a random 64-bit number as our transmit time. The NTP
@@ -300,7 +301,7 @@ write_packet(int fd, struct ntp_data *data)
300301
* the transmit field intelligible.
301302
*/
302303

303-
*(u_int64_t *)(packet + NTP_TRANSMIT) = data->xmitck;
304+
*(uint64_t *)(packet + NTP_TRANSMIT) = data->xmitck;
304305

305306
data->originate = current_time(JAN_1970);
306307

@@ -453,7 +454,7 @@ double
453454
current_time(double offset)
454455
{
455456
struct timeval current;
456-
u_int64_t t;
457+
uint64_t t;
457458

458459
if (gettimeofday(&current, NULL))
459460
err(1, "Could not get local time of day");

src/ntpleaps.c

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,13 @@
4545
#include <fcntl.h>
4646
#include <stdio.h>
4747
#include <stdlib.h>
48+
#include <stdint.h>
4849
#include <string.h>
4950
#include <unistd.h>
5051

5152
#include "ntpleaps.h"
5253

53-
static u_int64_t *leapsecs;
54+
static uint64_t *leapsecs;
5455
static unsigned int leapsecs_num;
5556

5657

@@ -81,10 +82,10 @@ ntpleaps_init(void)
8182
}
8283

8384
int
84-
ntpleaps_sub(u_int64_t *t)
85+
ntpleaps_sub(uint64_t *t)
8586
{
8687
unsigned int i = 0;
87-
u_int64_t u;
88+
uint64_t u;
8889
int r = 1;
8990

9091
if (ntpleaps_init() == -1)
@@ -105,10 +106,10 @@ ntpleaps_sub(u_int64_t *t)
105106
return (r);
106107
}
107108

108-
u_int32_t
109-
read_be_dword(u_int8_t *ptr)
109+
uint32_t
110+
read_be_dword(uint8_t *ptr)
110111
{
111-
u_int32_t res;
112+
uint32_t res;
112113

113114
memcpy(&res, ptr, 4);
114115
return (ntohl(res));
@@ -120,10 +121,10 @@ ntpleaps_read(void)
120121
{
121122
int fd;
122123
unsigned int r;
123-
u_int8_t buf[32];
124-
u_int32_t m1, m2, m3;
125-
u_int64_t s;
126-
u_int64_t *l;
124+
uint8_t buf[32];
125+
uint32_t m1, m2, m3;
126+
uint64_t s;
127+
uint64_t *l;
127128

128129
fd = open("/usr/share/zoneinfo/right/UTC", O_RDONLY | O_NDELAY);
129130
if (fd == -1)
@@ -153,7 +154,7 @@ ntpleaps_read(void)
153154
close(fd);
154155
return (-1);
155156
}
156-
if ((l = (u_int64_t *)malloc(r << 3)) == NULL) {
157+
if ((l = (uint64_t *)malloc(r << 3)) == NULL) {
157158
close(fd);
158159
return (-1);
159160
}

src/ntpleaps.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,13 @@
4646
#ifndef _NTPLEAPS_H
4747
#define _NTPLEAPS_H
4848

49+
#include <stdint.h>
50+
4951
/* Offset between struct timeval.tv_sec and a tai64_t */
5052
#define NTPLEAPS_OFFSET (4611686018427387914ULL)
5153

5254
/* Hide this ugly value from programmes */
53-
#define SEC_TO_TAI64(s) (NTPLEAPS_OFFSET + (u_int64_t)(s))
55+
#define SEC_TO_TAI64(s) (NTPLEAPS_OFFSET + (uint64_t)(s))
5456
#define TAI64_TO_SEC(t) ((t) - NTPLEAPS_OFFSET)
5557

5658
/* Initializes the leap second table. Does not need to be called
@@ -70,6 +72,6 @@ int ntpleaps_read(void);
7072
* to posix clock tick time.
7173
* returns 0 on success, -1 on error (time is unchanged), 1 on leap second
7274
*/
73-
int ntpleaps_sub(u_int64_t *);
75+
int ntpleaps_sub(uint64_t *);
7476

7577
#endif

src/rfc868time.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
#include <stdio.h>
5151
#include <ctype.h>
5252
#include <err.h>
53+
#include <stdint.h>
5354
#include <string.h>
5455
#include <netdb.h>
5556
#include <unistd.h>
@@ -68,10 +69,10 @@ rfc868time_client (const char *hostname, int family, struct timeval *new,
6869
{
6970
struct addrinfo hints, *res0, *res;
7071
struct timeval old;
71-
u_int32_t tim; /* RFC 868 states clearly this is an uint32 */
72+
uint32_t tim; /* RFC 868 states clearly this is an uint32 */
7273
int s;
7374
int error;
74-
u_int64_t td;
75+
uint64_t td;
7576

7677
memset(&hints, 0, sizeof(hints));
7778
hints.ai_family = family;

0 commit comments

Comments
 (0)