1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
/*
* tclUnixCompat.c
*
* Written by: Zoran Vasiljevic (vasiljevic@users.sourceforge.net).
*
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
* RCS: @(#) $Id: tclUnixCompat.c,v 1.8.6.2 2006/10/23 21:02:09 dgp Exp $
*
*/
#include "tclInt.h"
#include "tclPort.h"
#include <pwd.h>
#include <grp.h>
|
|
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
/*
* tclUnixCompat.c
*
* Written by: Zoran Vasiljevic (vasiljevic@users.sourceforge.net).
*
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
* RCS: @(#) $Id: tclUnixCompat.c,v 1.8.6.3 2007/04/16 18:36:03 dgp Exp $
*
*/
#include "tclInt.h"
#include "tclPort.h"
#include <pwd.h>
#include <grp.h>
|
| ︙ | | | ︙ | |
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
|
* Side effects:
* None.
*
*---------------------------------------------------------------------------
*/
static int
CopyArray(char **src, int elsize, char *buf, int buflen)
{
int i, j, len = 0;
char *p, **new;
if (src == NULL) {
return 0;
}
|
|
>
>
>
>
|
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
* Side effects:
* None.
*
*---------------------------------------------------------------------------
*/
static int
CopyArray(
char **src,
int elsize,
char *buf,
int buflen)
{
int i, j, len = 0;
char *p, **new;
if (src == NULL) {
return 0;
}
|
| ︙ | | | ︙ | |
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
|
* None
*
*---------------------------------------------------------------------------
*/
static int
CopyString(char *src, char *buf, int buflen)
{
int len = 0;
if (src != NULL) {
len += strlen(src) + 1;
if (len > buflen) {
return -1;
|
|
>
>
>
|
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
|
* None
*
*---------------------------------------------------------------------------
*/
static int
CopyString(
char *src,
char *buf,
int buflen)
{
int len = 0;
if (src != NULL) {
len += strlen(src) + 1;
if (len > buflen) {
return -1;
|
| ︙ | | | ︙ | |
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
|
* Side effects:
* None
*
*---------------------------------------------------------------------------
*/
static int
CopyHostent(struct hostent *tgtPtr, char *buf, int buflen)
{
char *p = buf;
int copied, len = 0;
copied = CopyString(tgtPtr->h_name, p, buflen - len);
if (copied == -1) {
range:
|
>
|
>
>
|
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
|
* Side effects:
* None
*
*---------------------------------------------------------------------------
*/
static int
CopyHostent(
struct hostent *tgtPtr,
char *buf,
int buflen)
{
char *p = buf;
int copied, len = 0;
copied = CopyString(tgtPtr->h_name, p, buflen - len);
if (copied == -1) {
range:
|
| ︙ | | | ︙ | |
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
|
* We are not copying the gecos field as it may not be supported
* on all platforms.
*
*---------------------------------------------------------------------------
*/
static int
CopyPwd(struct passwd *tgtPtr, char *buf, int buflen)
{
char *p = buf;
int copied, len = 0;
copied = CopyString(tgtPtr->pw_name, p, buflen - len);
if (copied == -1) {
range:
|
>
|
>
>
|
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
|
* We are not copying the gecos field as it may not be supported
* on all platforms.
*
*---------------------------------------------------------------------------
*/
static int
CopyPwd(
struct passwd *tgtPtr,
char *buf,
int buflen)
{
char *p = buf;
int copied, len = 0;
copied = CopyString(tgtPtr->pw_name, p, buflen - len);
if (copied == -1) {
range:
|
| ︙ | | | ︙ | |
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
|
* Side effects:
* None.
*
*---------------------------------------------------------------------------
*/
static int
CopyGrp(struct group *tgtPtr, char *buf, int buflen)
{
register char *p = buf;
register int copied, len = 0;
/* Copy username */
copied = CopyString(tgtPtr->gr_name, p, buflen - len);
if (copied == -1) {
|
>
|
>
>
|
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
|
* Side effects:
* None.
*
*---------------------------------------------------------------------------
*/
static int
CopyGrp(
struct group *tgtPtr,
char *buf,
int buflen)
{
register char *p = buf;
register int copied, len = 0;
/* Copy username */
copied = CopyString(tgtPtr->gr_name, p, buflen - len);
if (copied == -1) {
|
| ︙ | | | ︙ | |
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
|
* Side effects:
* None.
*
*---------------------------------------------------------------------------
*/
struct passwd *
TclpGetPwNam(const char *name)
{
#if !defined(TCL_THREADS)
return getpwnam(name);
#else
ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey);
#if defined(HAVE_GETPWNAM_R_5)
|
|
>
|
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
|
* Side effects:
* None.
*
*---------------------------------------------------------------------------
*/
struct passwd *
TclpGetPwNam(
const char *name)
{
#if !defined(TCL_THREADS)
return getpwnam(name);
#else
ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey);
#if defined(HAVE_GETPWNAM_R_5)
|
| ︙ | | | ︙ | |
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
|
* Side effects:
* None.
*
*---------------------------------------------------------------------------
*/
struct passwd *
TclpGetPwUid(uid_t uid)
{
#if !defined(TCL_THREADS)
return getpwuid(uid);
#else
ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey);
#if defined(HAVE_GETPWUID_R_5)
|
|
>
|
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
|
* Side effects:
* None.
*
*---------------------------------------------------------------------------
*/
struct passwd *
TclpGetPwUid(
uid_t uid)
{
#if !defined(TCL_THREADS)
return getpwuid(uid);
#else
ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey);
#if defined(HAVE_GETPWUID_R_5)
|
| ︙ | | | ︙ | |
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
|
* Side effects:
* None.
*
*---------------------------------------------------------------------------
*/
struct group *
TclpGetGrNam(const char *name)
{
#if !defined(TCL_THREADS)
return getgrnam(name);
#else
ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey);
#if defined(HAVE_GETGRNAM_R_5)
|
|
>
|
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
|
* Side effects:
* None.
*
*---------------------------------------------------------------------------
*/
struct group *
TclpGetGrNam(
const char *name)
{
#if !defined(TCL_THREADS)
return getgrnam(name);
#else
ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey);
#if defined(HAVE_GETGRNAM_R_5)
|
| ︙ | | | ︙ | |
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
|
* Side effects:
* None.
*
*---------------------------------------------------------------------------
*/
struct group *
TclpGetGrGid(gid_t gid)
{
#if !defined(TCL_THREADS)
return getgrgid(gid);
#else
ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey);
#if defined(HAVE_GETGRGID_R_5)
|
|
>
|
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
|
* Side effects:
* None.
*
*---------------------------------------------------------------------------
*/
struct group *
TclpGetGrGid(
gid_t gid)
{
#if !defined(TCL_THREADS)
return getgrgid(gid);
#else
ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey);
#if defined(HAVE_GETGRGID_R_5)
|
| ︙ | | | ︙ | |
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
|
* Side effects:
* None.
*
*---------------------------------------------------------------------------
*/
struct hostent *
TclpGetHostByName(const char *name)
{
#if !defined(TCL_THREADS) || defined(HAVE_MTSAFE_GETHOSTBYNAME)
return gethostbyname(name);
#else
ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey);
#if defined(HAVE_GETHOSTBYNAME_R_5)
|
|
>
|
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
|
* Side effects:
* None.
*
*---------------------------------------------------------------------------
*/
struct hostent *
TclpGetHostByName(
const char *name)
{
#if !defined(TCL_THREADS) || defined(HAVE_MTSAFE_GETHOSTBYNAME)
return gethostbyname(name);
#else
ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey);
#if defined(HAVE_GETHOSTBYNAME_R_5)
|
| ︙ | | | ︙ | |
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
|
* Side effects:
* None.
*
*---------------------------------------------------------------------------
*/
struct hostent *
TclpGetHostByAddr(const char *addr, int length, int type)
{
#if !defined(TCL_THREADS) || defined(HAVE_MTSAFE_GETHOSTBYADDR)
return gethostbyaddr(addr, length, type);
#else
ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey);
#if defined(HAVE_GETHOSTBYADDR_R_7)
|
|
>
>
>
|
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
|
* Side effects:
* None.
*
*---------------------------------------------------------------------------
*/
struct hostent *
TclpGetHostByAddr(
const char *addr,
int length,
int type)
{
#if !defined(TCL_THREADS) || defined(HAVE_MTSAFE_GETHOSTBYADDR)
return gethostbyaddr(addr, length, type);
#else
ThreadSpecificData *tsdPtr = TCL_TSD_INIT(&dataKey);
#if defined(HAVE_GETHOSTBYADDR_R_7)
|
| ︙ | | | ︙ | |