comparison mcabber/src/main.c @ 482:2ea7591584ab

Use fgets() instead of getline() getline() is not provided in FreeBSD (base install at least). Thanks to Vsevolod Stakhov.
author Mikael Berthe <mikael@lilotux.net>
date Wed, 05 Oct 2005 19:30:35 +0200
parents 0bb3d37579aa
children 9480a76471b6
comparison
equal deleted inserted replaced
481:fa9149832af2 482:2ea7591584ab
18 * along with this program; if not, write to the Free Software 18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 * USA 20 * USA
21 */ 21 */
22 22
23 #define _GNU_SOURCE
24 #include <stdio.h> 23 #include <stdio.h>
25 #include <stdlib.h> 24 #include <stdlib.h>
26 #include <unistd.h> 25 #include <unistd.h>
27 #include <string.h> 26 #include <string.h>
28 #include <signal.h> 27 #include <signal.h>
141 static void ask_password(void) 140 static void ask_password(void)
142 { 141 {
143 char *password, *p; 142 char *password, *p;
144 size_t passsize = 128; 143 size_t passsize = 128;
145 struct termios orig, new; 144 struct termios orig, new;
146 int nread; 145
146 password = g_new0(char, passsize);
147 147
148 /* Turn echoing off and fail if we can't. */ 148 /* Turn echoing off and fail if we can't. */
149 if (tcgetattr(fileno(stdin), &orig) != 0) return; 149 if (tcgetattr(fileno(stdin), &orig) != 0) return;
150 new = orig; 150 new = orig;
151 new.c_lflag &= ~ECHO; 151 new.c_lflag &= ~ECHO;
152 if (tcsetattr(fileno(stdin), TCSAFLUSH, &new) != 0) return; 152 if (tcsetattr(fileno(stdin), TCSAFLUSH, &new) != 0) return;
153 153
154 /* Read the password. */ 154 /* Read the password. */
155 password = NULL;
156 printf("Please enter password: "); 155 printf("Please enter password: ");
157 nread = getline(&password, &passsize, stdin); 156 fgets(password, passsize, stdin);
158 157
159 /* Restore terminal. */ 158 /* Restore terminal. */
160 tcsetattr(fileno(stdin), TCSAFLUSH, &orig); 159 tcsetattr(fileno(stdin), TCSAFLUSH, &orig);
161 printf("\n"); 160 printf("\n");
162
163 if (nread == -1 || !password) return;
164 161
165 for (p = (char*)password; *p; p++) 162 for (p = (char*)password; *p; p++)
166 ; 163 ;
167 for ( ; p > (char*)password ; p--) 164 for ( ; p > (char*)password ; p--)
168 if (*p == '\n' || *p == '\r') *p = 0; 165 if (*p == '\n' || *p == '\r') *p = 0;
169 166
170 settings_set(SETTINGS_TYPE_OPTION, "password", password); 167 settings_set(SETTINGS_TYPE_OPTION, "password", password);
171 free(password); 168 g_free(password);
172 return; 169 return;
173 } 170 }
174 171
175 inline static void credits(void) 172 inline static void credits(void)
176 { 173 {