0077-setlocale.c (947B)
1 #include <assert.h> 2 #include <locale.h> 3 #include <stdio.h> 4 #include <string.h> 5 6 /* 7 output: 8 testing 9 done 10 end: 11 */ 12 13 static int neg, pos; 14 15 static int 16 setup(void) 17 { 18 neg = LC_ALL; 19 if (neg > LC_COLLATE) 20 neg = LC_COLLATE; 21 if (neg > LC_CTYPE) 22 neg = LC_CTYPE; 23 if (neg > LC_MONETARY) 24 neg = LC_MONETARY; 25 if (neg > LC_NUMERIC) 26 neg = LC_NUMERIC; 27 if (neg > LC_TIME) 28 neg = LC_TIME; 29 --neg; 30 31 pos = LC_ALL; 32 if (pos < LC_COLLATE) 33 pos = LC_COLLATE; 34 if (pos < LC_CTYPE) 35 pos = LC_CTYPE; 36 if (pos < LC_MONETARY) 37 pos = LC_MONETARY; 38 if (pos < LC_NUMERIC) 39 pos = LC_NUMERIC; 40 if (pos < LC_TIME) 41 pos = LC_TIME; 42 ++pos; 43 44 return 0; 45 } 46 47 static void 48 run(void) 49 { 50 char *l1, *l2; 51 52 l1 = setlocale(LC_ALL, NULL); 53 assert(strcmp(l1, "C") == 0); 54 55 l1 = setlocale(pos, "C"); 56 l2 = setlocale(neg, "C"); 57 58 assert(l1 == NULL); 59 assert(l2 == NULL); 60 61 setlocale(LC_ALL, ""); 62 } 63 64 int 65 main(void) 66 { 67 puts("testing"); 68 setup(); 69 run(); 70 puts("done"); 71 72 return 0; 73 }