It's -fno-pic not -no-fpic.
[haiku.git] / src / bin / listsem.c
blobd066fcb8248aff31eaa94fa005006a75101a4fd7
1 /*
2 * listsem.c
4 * Lists all semaphores in all Teams.
5 * by O.Siebenmarck.
7 * 04-27-2002 - mmu_man
8 * added command line args
10 * Legal stuff follows:
12 Copyright (c) 2002 Oliver Siebenmarck <olli@ithome.de>, OpenBeOS project
14 Permission is hereby granted, free of charge, to any person obtaining a copy of
15 this software and associated documentation files (the "Software"), to deal in
16 the Software without restriction, including without limitation the rights to
17 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
18 of the Software, and to permit persons to whom the Software is furnished to do
19 so, subject to the following conditions:
21 The above copyright notice and this permission notice shall be included in all
22 copies or substantial portions of the Software.
24 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
25 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
27 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
29 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
30 THE SOFTWARE.
34 #include <stdio.h>
35 #include <stdlib.h>
36 #include <string.h>
37 #include <OS.h>
40 static void print_sem_info(sem_info *info)
42 printf("%7ld%31s%7ld\n", info->sem ,info->name , info->count);
46 static void print_header(team_info *tinfo)
48 if (tinfo != NULL)
49 printf("TEAM %ld (%s):\n", tinfo->team, tinfo->args );
51 printf(" ID name count\n");
52 printf("---------------------------------------------\n");
56 static void list_sems(team_info *tinfo)
58 sem_info info;
59 int32 cookie = 0;
61 print_header(tinfo);
63 while (get_next_sem_info(tinfo->team, &cookie, &info) == B_OK)
64 print_sem_info(&info);
66 printf("\n");
69 int main(int argc, char **argv)
71 team_info tinfo;
72 int32 cookie = 0;
73 int32 i;
74 system_info sysinfo;
76 // show up some stats first...
77 get_system_info(&sysinfo);
78 printf("sem: total: %5li, used: %5li, left: %5li\n\n", sysinfo.max_sems, sysinfo.used_sems, sysinfo.max_sems - sysinfo.used_sems);
80 if (argc == 1) {
81 while (get_next_team_info( &cookie, &tinfo) == B_OK)
82 list_sems(&tinfo);
84 return 0;
87 for (i = 1; i < argc; i++) {
88 if (strcmp(argv[i], "--help") == 0 || strcmp(argv[i], "-h") == 0) {
89 fprintf(stderr, "Usage: %s [-s semid] [teamid]\n", argv[0]);
90 fputs(" List the semaphores allocated by the specified\n",
91 stderr);
92 fputs(" team, or all teams if none is specified.\n",
93 stderr);
94 fputs("\n", stderr);
95 fputs(" The -s option displays the sem_info data for a\n",
96 stderr);
97 fputs(" specified semaphore.\n", stderr);
98 return 0;
99 } else if (strcmp(argv[i], "-s") == 0) {
100 if (argc < i + 2)
101 printf("-s used without associated sem id\n");
102 else {
103 sem_id id = atoi(argv[i + 1]);
104 sem_info info;
105 if (get_sem_info(id, &info) == B_OK) {
106 print_header(NULL);
107 print_sem_info(&info);
108 } else
109 printf("semaphore %ld unknown\n\n", id);
111 i++;
113 } else {
114 team_id team;
115 team = atoi(argv[i]);
116 if (get_team_info(team, &tinfo) == B_OK)
117 list_sems(&tinfo);
118 else
119 printf("team %ld unknown\n\n", team);
123 return 0;