csh and tcsh work

Sources of csh/getpwent.c

csh と tcsh のソース

Bill Joy

First published: October, 1978.

Copyright © 1979 Regents of the University of California.

  1. 1
    /* Copyright (c) 1979 Regents of the University of California */
  2. 2
    #include <pwd.h>
  3. 3
  4. 4
    #define	BUFSIZ	160
  5. 5
  6. 6
    static int pwf = -1;
  7. 7
    static char line[BUFSIZ+1];
  8. 8
    static struct passwd passwd;
  9. 9
  10. 10
    setpwent()
  11. 11
    {
  12. 12
    	if( pwf == -1 )
  13. 13
    		pwf = open( "/etc/passwd", 0 );
  14. 14
    	else
  15. 15
    		lseek(pwf, 0l, 0);
  16. 16
    }
  17. 17
  18. 18
    endpwent()
  19. 19
    {
  20. 20
    	if( pwf != -1 ){
  21. 21
    		close( pwf );
  22. 22
    		pwf = -1;
  23. 23
    	}
  24. 24
    }
  25. 25
  26. 26
    static char *
  27. 27
    pwskip(p)
  28. 28
    register char *p;
  29. 29
    {
  30. 30
    	while( *p && *p != ':' )
  31. 31
    		++p;
  32. 32
    	if( *p ) *p++ = 0;
  33. 33
    	return(p);
  34. 34
    }
  35. 35
  36. 36
    struct passwd *
  37. 37
    getpwent()
  38. 38
    {
  39. 39
    	register char *p, *q;
  40. 40
    	register int i, j;
  41. 41
  42. 42
    	if (pwf == -1) {
  43. 43
    		if( (pwf = open( "/etc/passwd", 0 )) == -1 )
  44. 44
    			return(0);
  45. 45
    	}
  46. 46
    	i = read(pwf, line, BUFSIZ);
  47. 47
    	for (j = 0; j < i; j++)
  48. 48
    		if (line[j] == '\n')
  49. 49
    			break;
  50. 50
    	if (j >= i)
  51. 51
    		return(0);
  52. 52
    	line[++j] = 0;
  53. 53
    	lseek(pwf, (long) (j - i), 1);
  54. 54
    	p = line;
  55. 55
    	passwd.pw_name = p;
  56. 56
    	p = pwskip(p);
  57. 57
    /*	passwd.pw_passwd = p; */
  58. 58
    	p = q = pwskip(p);
  59. 59
    /*	passwd.pw_uid = atoi(p); */
  60. 60
    	p = pwskip(p);
  61. 61
    	p[-1] = 0;
  62. 62
    	passwd.pw_uid = atou(q);
  63. 63
    /*	passwd.pw_gid = atoi(p); */
  64. 64
    /*	passwd.pw_quota = 0; */
  65. 65
    /*	passwd.pw_comment = ""; */
  66. 66
    	q = p;
  67. 67
    	p = pwskip(p);
  68. 68
    	p[-1] = 0;
  69. 69
    #ifdef CORY
  70. 70
    	passwd.pw_uid =+ atou(q) << 8;
  71. 71
    #endif
  72. 72
    #ifdef CC
  73. 73
    	passwd.pw_uid =+ atou(q) << 8;
  74. 74
    #endif
  75. 75
    #ifndef CORY
  76. 76
    #ifndef CC
  77. 77
    	passwd.pw_gid = atou(q);
  78. 78
    #endif
  79. 79
    #endif
  80. 80
    /*	passwd.pw_gecos = p; */
  81. 81
    	p = pwskip(p);
  82. 82
    	passwd.pw_dir = p;
  83. 83
    	p = pwskip(p);
  84. 84
    /*	passwd.pw_shell = p; */
  85. 85
    /* 	while(*p && *p != '\n') p++; */
  86. 86
    	*p = '\0';
  87. 87
    	return(&passwd);
  88. 88
    }
  89. 89
  90. 90
    atou(p)
  91. 91
    	register char *p;
  92. 92
    {
  93. 93
    	register int i = 0;
  94. 94
  95. 95
    	if (p != 0)
  96. 96
    		while (*p)
  97. 97
    			i = i * 10 + *p++ - '0';
  98. 98
    	return (i);
  99. 99
    }

To the top of this page