pipe_ino_test.c revision 228177
193250Sphk/*- 293250Sphk * Copyright (c) 2011 Giovanni Trematerra <giovanni.trematerra@gmail.com> 393250Sphk * All rights reserved. 493250Sphk * 593250Sphk * Redistribution and use in source and binary forms, with or without 693250Sphk * modification, are permitted provided that the following conditions 793250Sphk * are met: 893250Sphk * 1. Redistributions of source code must retain the above copyright 993250Sphk * notice, this list of conditions and the following disclaimer. 1093250Sphk * 2. Redistributions in binary form must reproduce the above copyright 1193250Sphk * notice, this list of conditions and the following disclaimer in the 1293250Sphk * documentation and/or other materials provided with the distribution. 1393250Sphk * 1493250Sphk * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1593250Sphk * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1693250Sphk * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1793250Sphk * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 1893250Sphk * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 1993250Sphk * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2093250Sphk * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2193250Sphk * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2293250Sphk * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2393250Sphk * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2493250Sphk * SUCH DAMAGE. 2593250Sphk */ 2693250Sphk 2793250Sphk/* 2893250Sphk * $FreeBSD: head/tools/regression/pipe/pipe-ino.c 228177 2011-12-01 11:20:25Z kib $ 2993250Sphk * Test conformance to stat(2) SUSv4 description: 3093250Sphk * "For all other file types defined in this volume of POSIX.1-2008, the 3193250Sphk * structure members st_mode, st_ino, st_dev, st_uid, st_gid, st_atim, 3293250Sphk * st_ctim, and st_mtim shall have meaningful values ...". 3393250Sphk * Check that st_dev and st_ino are meaningful. 3493250Sphk */ 3593250Sphk 3693250Sphk#include <sys/types.h> 3793250Sphk#include <sys/stat.h> 3893250Sphk#include <err.h> 3993250Sphk#include <stdio.h> 4093250Sphk#include <unistd.h> 4193250Sphk 4293250Sphkint 43110523Sphkmain(int argc, char **argv) 4493250Sphk{ 45104191Sphk int pipefd[2]; 46104191Sphk struct stat st1, st2; 47104191Sphk 48104191Sphk if (pipe(pipefd) == -1) 4993250Sphk err(1, "FAIL: pipe"); 5093250Sphk 5193250Sphk if (fstat(pipefd[0], &st1) == -1) 5293250Sphk err(1, "FAIL: fstat st1"); 5393250Sphk if (fstat(pipefd[1], &st2) == -1) 5493250Sphk err(1, "FAIL: fstat st2"); 5593250Sphk if (st1.st_dev != st2.st_dev || st1.st_dev == 0 || st2.st_dev == 0) { 5693250Sphk errx(1, "FAIL: wrong dev number %d %d", 5793250Sphk st1.st_dev, st2.st_dev); 58104056Sphk } 5993250Sphk if (st1.st_ino == st2.st_ino) 6093250Sphk errx(1, "FAIL: inode numbers are equal: %d", st1.st_ino); 6193250Sphk close(pipefd[0]); 6293250Sphk close(pipefd[1]); 6393250Sphk printf("PASS\n"); 6493250Sphk 6593250Sphk return (0); 6693250Sphk} 6793250Sphk