5-1.c revision 2c28215423293e443469a07ae7011135d058b671
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 munlockall() function always return a value of zero if it is 11 * supported by the implementation. 12 */ 13 14#include <unistd.h> 15#include <sys/mman.h> 16#include <stdio.h> 17#include <errno.h> 18#include "posixtest.h" 19 20#if !defined(_POSIX_MEMLOCK) || _POSIX_MEMLOCK == -1 21 22int main() { 23 printf("Does not support ML (Memory Lock).\n"); 24 return PTS_UNSUPPORTED; 25} 26 27#else 28 29#if _POSIX_MEMLOCK != 0 30int main() { 31 int result; 32 33 result = munlockall(); 34 35 if (result == 0) { 36 printf("Test PASSED\n"); 37 return PTS_PASS; 38 } else if (errno == EPERM) { 39 printf("You don't have permission to unlock your address space.\nTry to rerun this test as root.\n"); 40 return PTS_UNRESOLVED; 41 } else { 42 printf("munlockall() returns %i instead of zero.\n", 43 result); 44 return PTS_FAIL; 45 } 46 47} 48 49#else 50 51int main() { 52 int result; 53 long memlock; 54 55 memlock = sysconf(_SC_MEMLOCK); 56 if (errno) { 57 perror("An errno occurs when calling sysconf().\n"); 58 return PTS_UNRESOLVED; 59 } 60 61 result = munlockall(); 62 63<<<<<<< HEAD 64 if ((result == 0 && memlock > 0) || (result == -1 && memlock <= 0)) { 65======= 66 if ((result == 0 && memlock > 0) || (result == -1 && memlock <= 0)){ 67>>>>>>> master 68 printf("Test PASSED\n"); 69 return PTS_PASS; 70 } else if (errno == EPERM) { 71 printf("You don't have permission to unlock your address space.\nTry to rerun this test as root.\n"); 72 return PTS_UNRESOLVED; 73 } else { 74 printf("munlockall() returns %i instead of zero.\n", 75 result); 76 return PTS_FAIL; 77 } 78 79} 80 81#endif 82 83#endif