Home | History | Annotate | Download | only in shm_open
      1 /*
      2  *  This program is free software; you can redistribute it and/or modify
      3  *  it under the terms of the GNU General Public License version 2.
      4  *
      5  *  This program is distributed in the hope that it will be useful,
      6  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
      7  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      8  *  GNU General Public License for more details.
      9  *
     10  * Test that the shm_open() function sets errno = EMFILE if too many file
     11  * descriptors are currently in use by this process.
     12  */
     13 
     14 #include <stdio.h>
     15 #include <sys/mman.h>
     16 #include <sys/stat.h>
     17 #include <fcntl.h>
     18 #include <errno.h>
     19 #include "posixtest.h"
     20 
     21 #define SHM_NAME "posixtest_38-1"
     22 
     23 int main(void)
     24 {
     25 	int fd = 0, count = 0;
     26 
     27 	while (fd != -1) {
     28 		fd = shm_open(SHM_NAME, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR);
     29 		count++;
     30 	}
     31 	if (errno == EMFILE) {
     32 		shm_unlink(SHM_NAME);
     33 		printf("Test PASSED: %i files open.\n", count);
     34 		return PTS_PASS;
     35 	}
     36 	perror("shm_open");
     37 	shm_unlink(SHM_NAME);
     38 	return PTS_FAIL;
     39 }
     40