File: pr104369-2.c

package info (click to toggle)
gcc-arm-none-eabi 15%3A12.2.rel1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 959,712 kB
  • sloc: cpp: 3,275,382; ansic: 2,061,766; ada: 840,956; f90: 208,513; makefile: 76,132; asm: 73,433; xml: 50,448; exp: 34,146; sh: 32,436; objc: 15,637; fortran: 14,012; python: 11,991; pascal: 6,787; awk: 4,779; perl: 3,054; yacc: 338; ml: 285; lex: 201; haskell: 122
file content (79 lines) | stat: -rw-r--r-- 1,792 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
typedef __SIZE_TYPE__ size_t;
#define NULL ((void *)0)
#define POLLIN 0x001

typedef struct {
  unsigned long int __val[(1024 / (8 * sizeof(unsigned long int)))];
} __sigset_t;

typedef unsigned int socklen_t;

struct timespec {
  /* [...snip...] */
};

typedef unsigned long int nfds_t;

struct pollfd {
  int fd;
  short int events;
  short int revents;
};

extern int ppoll(struct pollfd *__fds, nfds_t __nfds,
                 const struct timespec *__timeout, const __sigset_t *__ss);

struct sockaddr_un {
  /* [...snip...] */
  char sun_path[108];
};

typedef union {
  /* [...snip...] */
  struct sockaddr_un *__restrict __sockaddr_un__;
  /* [...snip...] */
} __SOCKADDR_ARG __attribute__((transparent_union));

extern int accept(int __fd, __SOCKADDR_ARG __addr,
                  socklen_t *__restrict __addr_len);

extern void *calloc(size_t __nmemb, size_t __size)
  __attribute__((__nothrow__, __leaf__))
  __attribute__((__malloc__))
  __attribute__((__alloc_size__(1, 2)));

extern void *realloc(void *__ptr, size_t __size)
  __attribute__((__nothrow__, __leaf__))
  __attribute__((__warn_unused_result__))
  __attribute__((__alloc_size__(2)));

extern void exit(int __status)
  __attribute__((__nothrow__, __leaf__))
  __attribute__((__noreturn__));

int main() {
  int rc;
  int nsockets = 1;
  struct pollfd *pollfds, *newpollfds;
  struct sockaddr_un remote;
  socklen_t len = sizeof(remote);

  pollfds = calloc(1, sizeof(struct pollfd));
  if (!pollfds) {
    exit(1);
  }

  rc = ppoll(pollfds, nsockets, NULL, NULL);
  if (rc < 0) {
    exit(2);
  }

  nsockets++;
  newpollfds = realloc(pollfds, nsockets * sizeof(*pollfds));
  if (!newpollfds) {
    exit(3);
  }
  pollfds = newpollfds;
  pollfds[nsockets - 1].fd = accept(pollfds[0].fd, &remote, &len);
  exit(4);
}