users.c (f22acdfff536d452df49dd85c5ecd42092b8fcad) | users.c (23a1ccea6aac035f084a7a4cdc968687d1b02daf) |
---|---|
1/* | 1/* |
2 * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 3 * Use is subject to license terms. | 2 * Copyright (c) 1990, 2010, Oracle and/or its affiliates. All rights reserved. |
4 */ 5 6/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 7/* All Rights Reserved */ 8 | 3 */ 4 5/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 6/* All Rights Reserved */ 7 |
9 | |
10/* 11 * Copyright (c) 1980 Regents of the University of California. 12 * All rights reserved. The Berkeley software License Agreement 13 * specifies the terms and conditions for redistribution. 14 */ 15 | 8/* 9 * Copyright (c) 1980 Regents of the University of California. 10 * All rights reserved. The Berkeley software License Agreement 11 * specifies the terms and conditions for redistribution. 12 */ 13 |
16#pragma ident "%Z%%M% %I% %E% SMI" 17 | |
18/* 19 * users 20 */ 21 22#include <stdio.h> 23#include <sys/types.h> 24#include <stdlib.h> 25#include <utmpx.h> 26#include <string.h> 27 28static char **names; 29static char **namp; 30 | 14/* 15 * users 16 */ 17 18#include <stdio.h> 19#include <sys/types.h> 20#include <stdlib.h> 21#include <utmpx.h> 22#include <string.h> 23 24static char **names; 25static char **namp; 26 |
31static char *strndup(char *p, int n); | |
32static int scmp(const void *p, const void *q); 33static void summary(void); 34 35int 36main(int argc, char **argv) 37{ 38 int nusers = 0; 39 int bufflen = BUFSIZ; --- 14 unchanged lines hidden (view full) --- 54 continue; 55 if (utmpx->ut_type != USER_PROCESS) 56 continue; 57 if (nonuserx(*utmpx)) 58 continue; 59 if (nusers == bufflen) { 60 bufflen *= 2; 61 names = (char **)realloc(names, | 27static int scmp(const void *p, const void *q); 28static void summary(void); 29 30int 31main(int argc, char **argv) 32{ 33 int nusers = 0; 34 int bufflen = BUFSIZ; --- 14 unchanged lines hidden (view full) --- 49 continue; 50 if (utmpx->ut_type != USER_PROCESS) 51 continue; 52 if (nonuserx(*utmpx)) 53 continue; 54 if (nusers == bufflen) { 55 bufflen *= 2; 56 names = (char **)realloc(names, |
62 bufflen * sizeof (char *)); | 57 bufflen * sizeof (char *)); |
63 namp = names + nusers; 64 } 65 *namp++ = strndup(utmpx->ut_name, sizeof (utmpx->ut_name)); 66 nusers++; 67 } 68 69 endutxent(); 70 71 summary(); 72 return (0); 73} 74 | 58 namp = names + nusers; 59 } 60 *namp++ = strndup(utmpx->ut_name, sizeof (utmpx->ut_name)); 61 nusers++; 62 } 63 64 endutxent(); 65 66 summary(); 67 return (0); 68} 69 |
75static char * 76strndup(char *p, int n) 77{ 78 79 register char *x; 80 x = malloc(n + 1); 81 (void) strlcpy(x, p, n + 1); 82 return (x); 83 84} 85 | |
86static int 87scmp(const void *p, const void *q) 88{ 89 return (strcmp((char *)p, (char *)q)); 90} 91 92static void 93summary(void) --- 12 unchanged lines hidden --- | 70static int 71scmp(const void *p, const void *q) 72{ 73 return (strcmp((char *)p, (char *)q)); 74} 75 76static void 77summary(void) --- 12 unchanged lines hidden --- |