File: common.h

package info (click to toggle)
nvtop 3.2.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,292 kB
  • sloc: ansic: 13,121; objc: 181; cpp: 156; sh: 70; makefile: 3
file content (54 lines) | stat: -rw-r--r-- 1,653 bytes parent folder | download | duplicates (3)
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
/*
 *
 * Copyright (C) 2022 Maxime Schmitt <maxime.schmitt91@gmail.com>
 *
 * This file is part of Nvtop.
 *
 * Nvtop is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Nvtop is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with nvtop.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

#ifndef NVTOP_COMMON_H__
#define NVTOP_COMMON_H__

#if !defined(HAS_REALLOCARRAY)

#include <errno.h>
#include <stdlib.h>

#undef reallocarray

// Reallocarray from musl libc (https://git.musl-libc.org/cgit/musl/tree/src/malloc/reallocarray.c)
static void *nvtop_reallocarray__(void *ptr, size_t nmemb, size_t size) {
  if (size && nmemb > -1 / size) {
    errno = ENOMEM;
    return NULL;
  }
  return realloc(ptr, nmemb * size);
}
#define reallocarray(ptr, nmemb, size) nvtop_reallocarray__(ptr, nmemb, size)

#endif // !defined(HAS_REALLOCARRAY)

// Increment for the number of tracked processes
// 16 has been experimentally selected for being small while avoiding multipe allocations in most common cases
#define COMMON_PROCESS_LINEAR_REALLOC_INC 16

#define MAX_LINES_PER_PLOT 4

// Helper macro to stringify an integer
#define QUOTE(x) #x
#define EXPAND_AND_QUOTE(x) QUOTE(x)

#endif // NVTOP_COMMON_H__