aboutsummaryrefslogtreecommitdiffstats
path: root/libpatch_is_devnull.c
blob: 3a78ea647cb587c7c69e4aa424ac4b5048e1b78a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/* See LICENSE file for copyright and license details. */
#include "common.h"
#include <sys/sysmacros.h>


int
libpatch_is_devnull(int fd)
{
	struct stat fd_st;
#ifndef __linux__
	struct stat null_st;
#endif
	if (fstat(fd, &fd_st))
		return -1;
	if (!S_ISCHR(fd_st.st_mode))
		return 0;
#ifdef __linux__
	return fd_st.st_rdev == makedev(1, 3);
#else
	if (stat("/dev/null", &null_st))
		return -1;
	return fd_st.st_rdev == null_st.st_rdev;
#endif
}