Renamed SOCKLEN_T as EXIM_SOCKLEN_T to avoid a problem in AIX.
[exim.git] / src / OS / os.c-Linux-libc5
CommitLineData
61ec970d
PH
1/* $Cambridge: exim/src/OS/os.c-Linux-libc5,v 1.1 2004/10/06 15:07:39 ph10 Exp $ */
2
3/*************************************************
4* Exim - an Internet mail transport agent *
5*************************************************/
6
7/* Copyright (c) University of Cambridge 2001 */
8/* See the file NOTICE for conditions of use and distribution. */
9
10/* Linux-specific code. This is concatenated onto the generic src/os.c file.
11Linux has an apparently unique way of getting the load average, so we provide a
12unique function here, and define OS_LOAD_AVERAGE to stop src/os.c trying to
13provide the function. The macro may be set initially anyway, when compiling os.
14for utilities that don't want this function. */
15
16#ifndef OS_LOAD_AVERAGE
17#define OS_LOAD_AVERAGE
18
19int
20os_getloadavg(void)
21{
22char buffer[40];
23double avg;
24int count;
25int fd = open ("/proc/loadavg", O_RDONLY);
26if (fd == -1) return -1;
27count = read (fd, buffer, sizeof(buffer));
28(void)close (fd);
29if (count <= 0) return -1;
30count = sscanf (buffer, "%lf", &avg);
31if (count < 1) return -1;
32
33return (int)(avg * 1000.0);
34}
35
36#endif /* OS_LOAD_AVERAGE */
37
38/* End of os.c-Linux */
39