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
214ca2bbdcd3003f3c8df4e6129e9c7b2bd1514f87Cyril Hrubisint main(void)
22354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao{
230dc076565f772bb1953209fb69ea150b494aaa40robbiew	int result;
242c28215423293e443469a07ae7011135d058b671Garrett Cooper
250dc076565f772bb1953209fb69ea150b494aaa40robbiew	/* Ensure that the name SHM_NAME is removed */
260dc076565f772bb1953209fb69ea150b494aaa40robbiew	shm_unlink(SHM_NAME);
270dc076565f772bb1953209fb69ea150b494aaa40robbiew
280dc076565f772bb1953209fb69ea150b494aaa40robbiew	result = shm_unlink(SHM_NAME);
292c28215423293e443469a07ae7011135d058b671Garrett Cooper
30df3eb16e38c6a163b0a7367c885679eed6140964Garrett Cooper	if (result == -1 && errno == ENOENT) {
310dc076565f772bb1953209fb69ea150b494aaa40robbiew		printf("Test PASSED\n");
320dc076565f772bb1953209fb69ea150b494aaa40robbiew		return PTS_PASS;
330dc076565f772bb1953209fb69ea150b494aaa40robbiew	} else if (result == -1) {
340dc076565f772bb1953209fb69ea150b494aaa40robbiew		perror("Unexpected error");
350dc076565f772bb1953209fb69ea150b494aaa40robbiew		return PTS_UNRESOLVED;
360dc076565f772bb1953209fb69ea150b494aaa40robbiew	}
370dc076565f772bb1953209fb69ea150b494aaa40robbiew
380dc076565f772bb1953209fb69ea150b494aaa40robbiew	printf("shm_unlink() success.");
390dc076565f772bb1953209fb69ea150b494aaa40robbiew	return PTS_FAIL;
402c28215423293e443469a07ae7011135d058b671Garrett Cooper
41ec6edca7aa42b6affd989ef91b5897f96795e40fChris Dearman}
42