11-1.c revision 2c28215423293e443469a07ae7011135d058b671
10dc076565f772bb1953209fb69ea150b494aaa40robbiew/*
20dc076565f772bb1953209fb69ea150b494aaa40robbiew *  This program is free software; you can redistribute it and/or modify
30dc076565f772bb1953209fb69ea150b494aaa40robbiew *  it under the terms of the GNU General Public License version 2.
40dc076565f772bb1953209fb69ea150b494aaa40robbiew *
50dc076565f772bb1953209fb69ea150b494aaa40robbiew *  This program is distributed in the hope that it will be useful,
60dc076565f772bb1953209fb69ea150b494aaa40robbiew *  but WITHOUT ANY WARRANTY; without even the implied warranty of
70dc076565f772bb1953209fb69ea150b494aaa40robbiew *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
80dc076565f772bb1953209fb69ea150b494aaa40robbiew *  GNU General Public License for more details.
90dc076565f772bb1953209fb69ea150b494aaa40robbiew *
100dc076565f772bb1953209fb69ea150b494aaa40robbiew * Test that the shm_unlink() function sets errno = ENOENT  if the named shared
110dc076565f772bb1953209fb69ea150b494aaa40robbiew * memory object does not exist.
120dc076565f772bb1953209fb69ea150b494aaa40robbiew */
130dc076565f772bb1953209fb69ea150b494aaa40robbiew
140dc076565f772bb1953209fb69ea150b494aaa40robbiew#include <stdio.h>
150dc076565f772bb1953209fb69ea150b494aaa40robbiew#include <sys/mman.h>
160dc076565f772bb1953209fb69ea150b494aaa40robbiew#include <errno.h>
170dc076565f772bb1953209fb69ea150b494aaa40robbiew#include "posixtest.h"
180dc076565f772bb1953209fb69ea150b494aaa40robbiew
190dc076565f772bb1953209fb69ea150b494aaa40robbiew#define SHM_NAME "posixtest_11-1"
200dc076565f772bb1953209fb69ea150b494aaa40robbiew
210dc076565f772bb1953209fb69ea150b494aaa40robbiewint main() {
220dc076565f772bb1953209fb69ea150b494aaa40robbiew	int result;
232c28215423293e443469a07ae7011135d058b671Garrett Cooper
240dc076565f772bb1953209fb69ea150b494aaa40robbiew	/* Ensure that the name SHM_NAME is removed */
250dc076565f772bb1953209fb69ea150b494aaa40robbiew	shm_unlink(SHM_NAME);
260dc076565f772bb1953209fb69ea150b494aaa40robbiew
270dc076565f772bb1953209fb69ea150b494aaa40robbiew	result = shm_unlink(SHM_NAME);
282c28215423293e443469a07ae7011135d058b671Garrett Cooper
29df3eb16e38c6a163b0a7367c885679eed6140964Garrett Cooper	if (result == -1 && errno == ENOENT) {
300dc076565f772bb1953209fb69ea150b494aaa40robbiew		printf("Test PASSED\n");
310dc076565f772bb1953209fb69ea150b494aaa40robbiew		return PTS_PASS;
320dc076565f772bb1953209fb69ea150b494aaa40robbiew	} else if (result == -1) {
330dc076565f772bb1953209fb69ea150b494aaa40robbiew		perror("Unexpected error");
340dc076565f772bb1953209fb69ea150b494aaa40robbiew		return PTS_UNRESOLVED;
350dc076565f772bb1953209fb69ea150b494aaa40robbiew	}
360dc076565f772bb1953209fb69ea150b494aaa40robbiew
370dc076565f772bb1953209fb69ea150b494aaa40robbiew	printf("shm_unlink() success.");
380dc076565f772bb1953209fb69ea150b494aaa40robbiew	return PTS_FAIL;
392c28215423293e443469a07ae7011135d058b671Garrett Cooper
402c28215423293e443469a07ae7011135d058b671Garrett Cooper}