1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
|
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License, Version 1.0 only
# (the "License"). You may not use this file except in compliance
# with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# or http://www.opensolaris.org/os/licensing.
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
# Copyright (c) 1989 by Sun Microsystems, Inc.
# Copyright (c) 2018, Joyent, Inc.
#
LIBS= a.a
OBJS= pnpsplit.o devtolin.o expand.o lintodev.o \
namtouid.o tmless.o tmsecs.o uidtonam.o substr.o
SRCS= $(OBJS:%.o=%.c)
include ../../Makefile.cmd
CPPFLAGS = -D_LTYPES -I.. $(CPPFLAGS.master)
CERRWARN += -Wno-implicit-function-declaration
CERRWARN += -Wno-parentheses
CERRWARN += -Wno-extra
# not linted
SMATCH=off
.KEEP_STATE:
.PARALLEL: $(OBJS)
all: $(LIBS)
$(LIBS): $(OBJS)
$(AR) $(ARFLAGS) $@ $(OBJS)
clean:
$(RM) $(OBJS)
clobber: clean
$(RM) $(LIBS)
lint:
$(LINT.c) $(SRCS)
install:
.PRECIOUS: $(LIBS)
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
/*
* Copyright 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* convert device to linename (as in /dev/linename)
* return ptr to LSZ-byte string, "?" if not found
* device must be character device
* maintains small list in tlist structure for speed
*/
#include <stdio.h>
#include <sys/types.h>
#include <sys/param.h>
#include "acctdef.h"
#include <dirent.h>
#include <string.h>
#include <sys/stat.h>
static int tsize1;
static struct tlist {
char tname[LSZ]; /* linename */
dev_t tdev; /* device */
} tl[TSIZE1];
char *strncpy();
dev_t lintodev();
static char dev_dir[] = "/dev";
static char *def_srch_dirs[] = {
"/dev/term",
"/dev/pts",
"/dev/xt",
NULL
};
char file_name[MAX_DEV_PATH]; /* name being returned */
static int srch_dir();
char *
devtolin(dev_t device)
{
struct tlist *tp;
char **srch_dirs; /* priority directories to search first */
int found = 0;
int dirno = 0;
for (tp = tl; tp < &tl[tsize1]; tp++)
if (device == tp->tdev)
return (tp->tname);
srch_dirs = def_srch_dirs;
while ((!found) && (srch_dirs[dirno] != NULL)) {
/*
* if /dev is one of the priority directories we should only
* search its top level for now (set depth = MAX_SEARCH_DEPTH)
*/
found = srch_dir(device, srch_dirs[dirno],
((strcmp(srch_dirs[dirno], dev_dir) == 0) ?
MAX_SRCH_DEPTH : 1), NULL);
dirno++;
}
/*
* if not yet found search remaining /dev directory skipping the
* priority directories
*/
if (!found)
found = srch_dir(device, dev_dir, 0, srch_dirs);
/*
* if found then put it (without the "/dev/" prefix) in the tlist
* structure and return the path name without the "/dev/" prefix
*/
if (found) {
if (tsize1 < TSIZE1) {
tp->tdev = device;
CPYN(tp->tname, file_name+5);
tsize1++;
}
return (file_name+5);
} else {
/*
* if not found put "?" in the tlist structure for that device
* and return "?"
*/
if (tsize1 < TSIZE1) {
tp->tdev = device;
CPYN(tp->tname, "?");
tsize1++;
}
}
return ("?");
}
/*
* Arguments:
* device device we are looking for
* path current path
* depth current depth
* skip_dirs directories that don't need searched
*/
static int
srch_dir(dev_t device, char *path, int depth, char *skip_dirs[])
{
DIR *fdev;
struct dirent *d;
int dirno = 0;
int found = 0;
int path_len;
char *last_comp;
struct stat sb;
/* do we need to search this directory? */
if ((skip_dirs != NULL) && (depth != 0))
while (skip_dirs[dirno] != NULL)
if (strcmp(skip_dirs[dirno++], path) == 0)
return (0);
/* open the directory */
if ((fdev = opendir(path)) == NULL)
return (0);
/* initialize file name using path name */
path_len = strlen(path);
strcpy(file_name, path);
last_comp = file_name + path_len;
*last_comp++ = '/';
/* start searching this directory */
while ((!found) && ((d = readdir(fdev)) != NULL)) {
if (d->d_ino != 0) {
/*
* if name would not be too long append it to
* directory name, otherwise skip this entry
*/
if ((int)(path_len + strlen(d->d_name) + 2) >
MAX_DEV_PATH)
continue;
else
strcpy(last_comp, d->d_name);
/*
* if this directory entry has the device number we
* need, then the name is found. Otherwise if it's a
* directory (not . or ..) and we haven't gone too
* deep, recurse.
*/
if (lintodev(file_name+5) == device) {
found = 1;
break;
} else if ((depth < MAX_SRCH_DEPTH) &&
(strcmp(d->d_name, ".") != 0) &&
(strcmp(d->d_name, "..") != 0) &&
(stat(file_name, &sb) != -1) &&
((sb.st_mode & S_IFMT) == S_IFDIR)) {
found = srch_dir(device, file_name, depth+1,
skip_dirs);
}
}
}
closedir(fdev);
return (found);
}
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
#include <sys/types.h>
#include <sys/param.h>
#include <sys/acct.h>
#ifdef uts
float
#else
/*
* For as long as ct is of type comp_t, and comp_t is defined to be of type
* unsigned short, the maximum value of ct will be 2^16-1 ie 65535. Based on
* this input value, the maximum value that expand() can return will therefore
* be 4292870144. A return type of ulong_t ensures we don't overflow.
*/
ulong_t
#endif
expand(comp_t ct)
{
int e;
#ifdef uts
float f;
#else
ulong_t f;
#endif
e = (ct >> 13) & 07;
f = ct & 017777;
while (e-- > 0)
#ifdef uts
f *= 8.0; /* can't shift a float */
#else
f <<=3;
#endif
return f;
}
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.9 */
/*
* convert linename to device
* return -1 if nonexistent or not character device
*/
#include <stdio.h>
#include <sys/types.h>
#include <sys/param.h>
#include <sys/stat.h>
#include "acctdef.h"
static char devtty[5+LSZ+1] = "/dev/xxxxxxxx";
char *strncpy();
dev_t
lintodev(linename)
char linename[LSZ];
{
struct stat sb;
strncpy(&devtty[5], linename, LSZ);
if (stat(devtty, &sb) != -1 && (sb.st_mode&S_IFMT) == S_IFCHR)
return((dev_t)sb.st_rdev);
return((dev_t)NODEV);
}
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
/*
* Copyright 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* namtouid converts login names to uids
* maintains ulist for speed only
*/
#include <stdio.h>
#include <sys/types.h>
#include "acctdef.h"
#include <pwd.h>
static int usize;
static struct ulist {
char uname[NSZ];
uid_t uuid;
} ul[A_USIZE];
char ntmp[NSZ+1];
char *strncpy();
uid_t
namtouid(name)
char name[NSZ];
{
register struct ulist *up;
register uid_t tuid;
struct passwd *getpwnam(), *pp;
for (up = ul; up < &ul[usize]; up++)
if (strncmp(name, up->uname, NSZ) == 0)
return(up->uuid);
strncpy(ntmp, name, NSZ);
(void) setpwent();
if ((pp = getpwnam(ntmp)) == NULL)
tuid = -1;
else {
tuid = pp->pw_uid;
if (usize < A_USIZE) {
CPYN(up->uname, name);
up->uuid = tuid;
usize++;
}
}
return(tuid);
}
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
/*
* pnpsplit splits interval into prime & nonprime portions
* ONLY ROUTINE THAT KNOWS ABOUT HOLIDAYS AND DEFN OF PRIME/NONPRIME
*/
#include <stdio.h>
#include <sys/types.h>
#include <sys/param.h>
#include "acctdef.h"
#include <time.h>
#include <ctype.h>
/*
* validate that hours and minutes of prime/non-prime read in
* from holidays file fall within proper boundaries.
* Time is expected in the form and range of 0000-2400.
*/
static int thisyear = 1970; /* this is changed by holidays file */
static int holidays[NHOLIDAYS]; /* holidays file day-of-year table */
static int day_tab[2][13] = {
{0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
{0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
};
/*
* prime(0) and nonprime(1) times during a day
* for BTL, prime time is 9AM to 5PM
*/
static struct hours {
int h_sec; /* normally always zero */
int h_min; /* initialized from holidays file (time%100) */
int h_hour; /* initialized from holidays file (time/100) */
long h_type; /* prime/nonprime of previous period */
} h[4];
/* the sec, min, hr of the day's end */
struct tm daysend = {
.tm_sec = 0,
.tm_min = 60,
.tm_hour = 23
};
long tmsecs(struct tm *, struct tm *);
/*
* split interval of length etime, starting at start into prime/nonprime
* values, return as result
* input values in seconds
*/
int
pnpsplit(long start, ulong_t etime, long result[2])
{
struct tm cur, end, hours;
time_t tcur, tend;
long tmp;
int sameday;
struct hours *hp;
/* once holidays file is read, this is zero */
if(thisyear && (checkhol() == 0)) {
return(0);
}
tcur = start;
tend = start + etime;
memcpy(&end, localtime(&tend), sizeof(end));
result[PRIME] = 0;
result[NONPRIME] = 0;
while ( tcur < tend ) { /* one iteration per day or part thereof */
memcpy(&cur, localtime(&tcur), sizeof(cur));
sameday = cur.tm_yday == end.tm_yday;
if (ssh(&cur)) { /* ssh:only NONPRIME */
if (sameday) {
result[NONPRIME] += tend-tcur;
break;
} else {
tmp = tmsecs(&cur, &daysend);
result[NONPRIME] += tmp;
tcur += tmp;
}
} else { /* working day, PRIME or NONPRIME */
for (hp = h; tmless(hp, &cur); hp++);
for (; hp->h_sec >= 0; hp++) {
if (sameday && tmless(&end, hp)) {
/* WHCC mod, change from = to += 3/6/86 Paul */
result[hp->h_type] += tend-tcur;
tcur = tend;
break; /* all done */
} else { /* time to next PRIME /NONPRIME change */
hours.tm_sec = hp->h_sec;
hours.tm_min = hp->h_min;
hours.tm_hour = hp->h_hour;
tmp = tmsecs(&cur, &hours);
result[hp->h_type] += tmp;
tcur += tmp;
cur.tm_sec = hp->h_sec;
cur.tm_min = hp->h_min;
cur.tm_hour = hp->h_hour;
}
}
}
}
return(1);
}
/*
* Starting day after Christmas, complain if holidays not yet updated.
* This code is only executed once per program invocation.
*/
int
checkhol(void)
{
struct tm *tp;
time_t t;
if(inithol() == 0) {
fprintf(stderr, "pnpsplit: holidays table setup failed\n");
thisyear = 0;
holidays[0] = -1;
return(0);
}
time(&t);
tp = localtime(&t);
tp->tm_year += 1900;
if ((tp->tm_year == thisyear && tp->tm_yday > 359)
|| tp->tm_year > thisyear)
fprintf(stderr,
"***UPDATE %s WITH NEW HOLIDAYS***\n", HOLFILE);
thisyear = 0; /* checkhol() will not be called again */
return(1);
}
/*
* ssh returns 1 if Sat, Sun, or Holiday
*/
int
ssh(struct tm *ltp)
{
int i;
if (ltp->tm_wday == 0 || ltp->tm_wday == 6)
return(1);
for (i = 0; holidays[i] >= 0; i++)
if (ltp->tm_yday == holidays[i])
return(1);
return(0);
}
/*
* inithol - read from an ascii file and initialize the "thisyear"
* variable, the times that prime and non-prime start, and the
* holidays array.
*/
int
inithol(void)
{
FILE *holptr;
char holbuf[128];
int line = 0,
holindx = 0,
errflag = 0;
int pstart, npstart;
int doy; /* day of the year */
int month, day;
char *c;
if((holptr=fopen(HOLFILE, "r")) == NULL) {
perror(HOLFILE);
fclose(holptr);
return(0);
}
while(fgets(holbuf, sizeof(holbuf), holptr) != NULL) {
/* skip over blank lines and comments */
if (holbuf[0] == '*')
continue;
for (c = holbuf; isspace(*c); c++)
/* is a space */;
if (*c == '\0')
continue;
else if(++line == 1) { /* format: year p-start np-start */
if(sscanf(holbuf, "%4d %4d %4d",
&thisyear, &pstart, &npstart) != 3) {
fprintf(stderr,
"%s: bad {yr ptime nptime} conversion\n",
HOLFILE);
errflag++;
break;
}
/* validate year */
if(thisyear < 1970 || thisyear > 2037) {
fprintf(stderr, "pnpsplit: invalid year: %d\n",
thisyear);
errflag++;
break;
}
/* validate prime/nonprime hours */
if((! okay(pstart)) || (! okay(npstart))) {
fprintf(stderr,
"pnpsplit: invalid p/np hours\n");
errflag++;
break;
}
/* Set up start of prime time; 2400 == 0000 */
h[0].h_sec = 0;
h[0].h_min = pstart%100;
h[0].h_hour = (pstart/100==24) ? 0 : pstart/100;
h[0].h_type = NONPRIME;
/* Set up start of non-prime time; 2400 == 2360 */
if ((npstart/100) == 24) {
h[1].h_sec = 0;
h[1].h_min = 60;
h[1].h_hour = 23;
} else {
h[1].h_sec = 0;
h[1].h_min = npstart % 100;
h[1].h_hour = npstart / 100;
}
h[1].h_type = PRIME;
/* This is the end of the day */
h[2].h_sec = 0;
h[2].h_min = 60;
h[2].h_hour = 23;
h[2].h_type = NONPRIME;
/* The end of the array */
h[3].h_sec = -1;
continue;
}
else if(holindx >= NHOLIDAYS) {
fprintf(stderr, "pnpsplit: too many holidays, ");
fprintf(stderr, "recompile with larger NHOLIDAYS\n");
errflag++;
break;
}
/* Fill up holidays array from holidays file */
sscanf(holbuf, "%d/%d %*s %*s %*[^\n]\n", &month, &day);
if (month < 0 || month > 12) {
fprintf(stderr, "pnpsplit: invalid month %d\n", month);
errflag++;
break;
}
if (day < 0 || day > 31) {
fprintf(stderr, "pnpsplit: invalid day %d\n", day);
errflag++;
break;
}
doy = day_of_year(thisyear, month, day);
holidays[holindx++] = (doy - 1);
}
fclose(holptr);
if(!errflag && holindx < NHOLIDAYS) {
holidays[holindx] = -1;
return(1);
}
else
return(0);
}
/*
* tmsecs returns number of seconds from t1 to t2,
* times expressed in localtime format.
* assumed that t1 <= t2, and are in same day.
*/
long
tmsecs(struct tm *t1, struct tm *t2)
{
return((t2->tm_sec - t1->tm_sec) +
60*(t2->tm_min - t1->tm_min) +
3600L*(t2->tm_hour - t1->tm_hour));
}
/*
* return 1 if t1 earlier than t2 (times in localtime format)
* assumed that t1 and t2 are in same day
*/
int
tmless(struct tm *t1, struct tm *t2)
{
if (t1->tm_hour != t2->tm_hour)
return(t1->tm_hour < t2->tm_hour);
if (t1->tm_min != t2->tm_min)
return(t1->tm_min < t2->tm_min);
return(t1->tm_sec < t2->tm_sec);
}
/* set day of year from month and day */
int
day_of_year(int year, int month, int day)
{
int i, leap;
leap = year%4 == 0 && year%100 || year%400 == 0;
for (i = 1; i < month; i++)
day += day_tab[leap][i];
return(day);
}
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.5 */
/*
Place the `len' length substring of `as' starting at `as[origin]'
in `aresult'.
Return `aresult'.
Note: The copying of as to aresult stops if either the
specified number (len) characters have been copied,
or if the end of as is found.
A negative len generally guarantees that everything gets copied.
*/
char *substr(as, aresult, origin, len)
char *as, *aresult;
int origin;
register unsigned len;
{
register char *s, *result;
s = as + origin;
result = aresult;
++len;
while (--len && (*result++ = *s++)) ;
if (len == 0)
*result = 0;
return(aresult);
}
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
/*
* Copyright 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* return 1 if t1 earlier than t2 (times in localtime format)
* assumed that t1 and t2 are in same day
*/
#include <time.h>
int
tmless(t1, t2)
register struct tm *t1, *t2;
{
if (t1->tm_hour != t2->tm_hour)
return(t1->tm_hour < t2->tm_hour);
if (t1->tm_min != t2->tm_min)
return(t1->tm_min < t2->tm_min);
return(t1->tm_sec < t2->tm_sec);
}
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.5 */
/*
* tmsecs returns number of seconds from t1 to t2,
* times expressed in localtime format.
* assumed that t1 <= t2, and are in same day.
*/
#include <time.h>
long
tmsecs(t1, t2)
register struct tm *t1, *t2;
{
return((t2->tm_sec - t1->tm_sec) +
60*(t2->tm_min - t1->tm_min) +
3600L*(t2->tm_hour - t1->tm_hour));
}
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
/*
* Copyright 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* convert uid to login name; interface to getpwuid that keeps up to USIZE1
* names to avoid unnecessary accesses to passwd file
* returns ptr to NSZ-byte name (not necessarily null-terminated)
* returns ptr to "?" if cannot convert
*/
#include <stdio.h>
#include <sys/types.h>
#include <sys/param.h>
#include "acctdef.h"
#include <pwd.h>
static int usize1;
static struct ulist {
char uname[NSZ];
uid_t uuid;
} ul[USIZE1];
char *strncpy();
char *
uidtonam(uid)
uid_t uid;
{
register struct ulist *up;
struct passwd *getpwuid();
register struct passwd *pp;
for (up = ul; up < &ul[usize1]; up++)
if (uid == up->uuid)
return(up->uname);
setpwent();
if ((pp = getpwuid(uid)) == NULL)
return("?");
else {
if (usize1 < USIZE1) {
up->uuid = uid;
CPYN(up->uname, pp->pw_name);
usize1++;
}
return(pp->pw_name);
}
}
|