Index: pjproject/trunk/pjlib-util/src/pjlib-util-test/main.c
===================================================================
--- pjproject/trunk/pjlib-util/src/pjlib-util-test/main.c	(revision 2407)
+++ pjproject/trunk/pjlib-util/src/pjlib-util-test/main.c	(revision 2408)
@@ -55,5 +55,6 @@
 
 	puts("Press ENTER to quit");
-	fgets(s, sizeof(s), stdin);
+	if (fgets(s, sizeof(s), stdin) == NULL)
+	    return rc;
     }
 
Index: pjproject/trunk/pjlib/src/pjlib-test/main.c
===================================================================
--- pjproject/trunk/pjlib/src/pjlib-test/main.c	(revision 2407)
+++ pjproject/trunk/pjlib/src/pjlib-test/main.c	(revision 2408)
@@ -99,5 +99,6 @@
 	puts("");
 	puts("Press <ENTER> to exit");
-	fgets(s, sizeof(s), stdin);
+	if (!fgets(s, sizeof(s), stdin))
+	    return rc;
     }
 
Index: pjproject/trunk/pjmedia/src/test/main.c
===================================================================
--- pjproject/trunk/pjmedia/src/test/main.c	(revision 2407)
+++ pjproject/trunk/pjmedia/src/test/main.c	(revision 2408)
@@ -40,5 +40,6 @@
     if (argc == 2 && argv[1][0]=='-' && argv[1][1]=='i') {
 	puts("\nPress <ENTER> to quit");
-	fgets(s, sizeof(s), stdin);
+	if (fgets(s, sizeof(s), stdin) == NULL)
+	    return rc;
     }
 
Index: pjproject/trunk/pjmedia/src/test/rtp_test.c
===================================================================
--- pjproject/trunk/pjmedia/src/test/rtp_test.c	(revision 2407)
+++ pjproject/trunk/pjmedia/src/test/rtp_test.c	(revision 2408)
@@ -33,5 +33,8 @@
     pjmedia_rtp_session_init (&rtp, 4, 0x12345678);
     pjmedia_rtp_encode_rtp (&rtp, 4, 0, 0, 160, &rtphdr, &hdrlen);
-    fwrite (rtphdr, hdrlen, 1, fhnd);
+    if (fwrite (rtphdr, hdrlen, 1, fhnd) != 1) {
+	fclose(fhnd);
+	return -1;
+    }
     fclose(fhnd);
     return 0;
Index: pjproject/trunk/pjnath/src/pjnath-test/main.c
===================================================================
--- pjproject/trunk/pjnath/src/pjnath-test/main.c	(revision 2407)
+++ pjproject/trunk/pjnath/src/pjnath-test/main.c	(revision 2408)
@@ -54,5 +54,6 @@
 
 	puts("Press <ENTER> to exit");
-	fgets(buf, sizeof(buf), stdin);
+	if (fgets(buf, sizeof(buf), stdin) == NULL)
+	    return rc;
     }
 
Index: pjproject/trunk/pjnath/src/pjturn-client/client_main.c
===================================================================
--- pjproject/trunk/pjnath/src/pjturn-client/client_main.c	(revision 2407)
+++ pjproject/trunk/pjnath/src/pjturn-client/client_main.c	(revision 2408)
@@ -446,5 +446,6 @@
 	menu();
 
-	fgets(input, sizeof(input), stdin);
+	if (fgets(input, sizeof(input), stdin) == NULL)
+	    break;
 	
 	switch (input[0]) {
Index: pjproject/trunk/pjnath/src/pjturn-srv/main.c
===================================================================
--- pjproject/trunk/pjnath/src/pjturn-srv/main.c	(revision 2407)
+++ pjproject/trunk/pjnath/src/pjturn-srv/main.c	(revision 2408)
@@ -109,5 +109,6 @@
 	menu();
 	    
-	fgets(line, sizeof(line), stdin);
+	if (fgets(line, sizeof(line), stdin) == NULL)
+	    break;
 
 	switch (line[0]) {
Index: pjproject/trunk/pjsip-apps/src/pjsua/pjsua_app.c
===================================================================
--- pjproject/trunk/pjsip-apps/src/pjsua/pjsua_app.c	(revision 2407)
+++ pjproject/trunk/pjsip-apps/src/pjsua/pjsua_app.c	(revision 2408)
@@ -2751,5 +2751,6 @@
 
     printf("%s (empty to cancel): ", title); fflush(stdout);
-    fgets(buf, len, stdin);
+    if (fgets(buf, len, stdin) == NULL)
+	return PJ_FALSE;
 
     /* Remove trailing newlines. */
@@ -2795,5 +2796,6 @@
 
     fflush(stdout);
-    fgets(buf, len, stdin);
+    if (fgets(buf, len, stdin) == NULL)
+	return;
     len = strlen(buf);
 
@@ -3024,5 +3026,6 @@
 
     printf("Codec name (\"*\" for all) and priority: ");
-    fgets(input, sizeof(input), stdin);
+    if (fgets(input, sizeof(input), stdin) == NULL)
+	return;
     if (input[0]=='\r' || input[0]=='\n') {
 	puts("Done");
Index: pjproject/trunk/pjsip-apps/src/samples/confsample.c
===================================================================
--- pjproject/trunk/pjsip-apps/src/samples/confsample.c	(revision 2407)
+++ pjproject/trunk/pjsip-apps/src/samples/confsample.c	(revision 2408)
@@ -106,5 +106,6 @@
 
     printf("%s (empty to cancel): ", title); fflush(stdout);
-    fgets(buf, len, stdin);
+    if (fgets(buf, len, stdin) == NULL)
+	return PJ_FALSE;
 
     /* Remove trailing newlines. */
@@ -269,5 +270,5 @@
 	char tmp2[10];
 	char *err;
-	int src, dst, level;
+	int src, dst, level, dur;
 
 	puts("");
@@ -286,5 +287,6 @@
 	printf("Enter selection: "); fflush(stdout);
 
-	fgets(tmp, sizeof(tmp), stdin);
+	if (fgets(tmp, sizeof(tmp), stdin) == NULL)
+	    break;
 
 	switch (tmp[0]) {
@@ -416,5 +418,5 @@
 	    if (!input("Duration to monitor (in seconds)", tmp1, sizeof(tmp1)) )
 		continue;
-	    strtol(tmp1, &err, 10);
+	    dur = strtol(tmp1, &err, 10);
 	    if (*err) {
 		puts("Invalid duration number");
@@ -422,5 +424,5 @@
 	    }
 
-	    monitor_level(conf, src, tmp2[0], strtol(tmp1, &err, 10));
+	    monitor_level(conf, src, tmp2[0], dur);
 	    break;
 
Index: pjproject/trunk/pjsip-apps/src/samples/mix.c
===================================================================
--- pjproject/trunk/pjsip-apps/src/samples/mix.c	(revision 2407)
+++ pjproject/trunk/pjsip-apps/src/samples/mix.c	(revision 2408)
@@ -130,5 +130,6 @@
 	printf("File %s exists, overwrite? [Y/N] ", out_fname);
 	fflush(stdout);
-	fgets(in, sizeof(in), stdin);
+	if (fgets(in, sizeof(in), stdin) == NULL)
+	    return 1;
 	if (pj_tolower(in[0]) != 'y')
 	    return 1;
Index: pjproject/trunk/pjsip-apps/src/samples/pjsip-perf.c
===================================================================
--- pjproject/trunk/pjsip-apps/src/samples/pjsip-perf.c	(revision 2407)
+++ pjproject/trunk/pjsip-apps/src/samples/pjsip-perf.c	(revision 2408)
@@ -1810,5 +1810,5 @@
     } else {
 	/* Server mode */
-	char s[10];
+	char s[10], *unused;
 	pj_status_t status;
 	unsigned i;
@@ -1845,5 +1845,6 @@
 	puts("\nPress <ENTER> to quit\n");
 	fflush(stdout);
-	fgets(s, sizeof(s), stdin);
+	unused = fgets(s, sizeof(s), stdin);
+	PJ_UNUSED_ARG(unused);
 
 	app.thread_quit = PJ_TRUE;
Index: pjproject/trunk/pjsip-apps/src/samples/playfile.c
===================================================================
--- pjproject/trunk/pjsip-apps/src/samples/playfile.c	(revision 2407)
+++ pjproject/trunk/pjsip-apps/src/samples/playfile.c	(revision 2408)
@@ -173,5 +173,7 @@
     puts("Press <ENTER> to stop playing and quit");
 
-    fgets(tmp, sizeof(tmp), stdin);
+    if (fgets(tmp, sizeof(tmp), stdin) == NULL) {
+	puts("EOF while reading stdin, will quit now..");
+    }
 
     
Index: pjproject/trunk/pjsip-apps/src/samples/playsine.c
===================================================================
--- pjproject/trunk/pjsip-apps/src/samples/playsine.c	(revision 2407)
+++ pjproject/trunk/pjsip-apps/src/samples/playsine.c	(revision 2408)
@@ -278,5 +278,7 @@
     puts("Press <ENTER> to stop playing and quit");
 
-    fgets(tmp, sizeof(tmp), stdin);
+    if (fgets(tmp, sizeof(tmp), stdin) == NULL) {
+	puts("EOF while reading stdin, will quit now..");
+    }
 
     
Index: pjproject/trunk/pjsip-apps/src/samples/recfile.c
===================================================================
--- pjproject/trunk/pjsip-apps/src/samples/recfile.c	(revision 2407)
+++ pjproject/trunk/pjsip-apps/src/samples/recfile.c	(revision 2408)
@@ -168,5 +168,7 @@
     puts("Press <ENTER> to stop recording and quit");
 
-    fgets(tmp, sizeof(tmp), stdin);
+    if (fgets(tmp, sizeof(tmp), stdin) == NULL) {
+	puts("EOF while reading stdin, will quit now..");
+    }
 
     
Index: pjproject/trunk/pjsip-apps/src/samples/resampleplay.c
===================================================================
--- pjproject/trunk/pjsip-apps/src/samples/resampleplay.c	(revision 2407)
+++ pjproject/trunk/pjsip-apps/src/samples/resampleplay.c	(revision 2408)
@@ -191,6 +191,7 @@
     puts("Press <ENTER> to stop playing and quit");
 
-    fgets(tmp, sizeof(tmp), stdin);
-
+    if (fgets(tmp, sizeof(tmp), stdin) == NULL) {
+	puts("EOF while reading stdin, will quit now..");
+    }
     
     /* Start deinitialization: */
Index: pjproject/trunk/pjsip-apps/src/samples/simple_pjsua.c
===================================================================
--- pjproject/trunk/pjsip-apps/src/samples/simple_pjsua.c	(revision 2407)
+++ pjproject/trunk/pjsip-apps/src/samples/simple_pjsua.c	(revision 2408)
@@ -183,5 +183,8 @@
 
 	puts("Press 'h' to hangup all calls, 'q' to quit");
-	fgets(option, sizeof(option), stdin);
+	if (fgets(option, sizeof(option), stdin) == NULL) {
+	    puts("EOF while reading stdin, will quit now..");
+	    break;
+	}
 
 	if (option[0] == 'q')
Index: pjproject/trunk/pjsip-apps/src/samples/siprtp.c
===================================================================
--- pjproject/trunk/pjsip-apps/src/samples/siprtp.c	(revision 2407)
+++ pjproject/trunk/pjsip-apps/src/samples/siprtp.c	(revision 2408)
@@ -1863,5 +1863,6 @@
 
     printf("%s (empty to cancel): ", title); fflush(stdout);
-    fgets(buf, len, stdin);
+    if (fgets(buf, len, stdin) == NULL)
+	return PJ_FALSE;
 
     /* Remove trailing newlines. */
@@ -1899,5 +1900,8 @@
     for (;;) {
 	printf(">>> "); fflush(stdout);
-	fgets(input1, sizeof(input1), stdin);
+	if (fgets(input1, sizeof(input1), stdin) == NULL) {
+	    puts("EOF while reading stdin, will quit now..");
+	    break;
+	}
 
 	switch (input1[0]) {
@@ -2021,5 +2025,6 @@
 
     if (log_file) {
-	fwrite(buffer, len, 1, log_file);
+	int count = fwrite(buffer, len, 1, log_file);
+	PJ_UNUSED_ARG(count);
 	fflush(log_file);
     }
Index: pjproject/trunk/pjsip-apps/src/samples/sndinfo.c
===================================================================
--- pjproject/trunk/pjsip-apps/src/samples/sndinfo.c	(revision 2407)
+++ pjproject/trunk/pjsip-apps/src/samples/sndinfo.c	(revision 2408)
@@ -203,6 +203,7 @@
     //pj_thread_sleep(1000);
     puts("Press <ENTER> to stop");
-    fgets(tmp, sizeof(tmp), stdin);
-
+    if (fgets(tmp, sizeof(tmp), stdin) == NULL) {
+	puts("EOF while reading stdin, will quit now..");
+    }
 
     pjmedia_snd_stream_close(strm);
Index: pjproject/trunk/pjsip-apps/src/samples/stateful_proxy.c
===================================================================
--- pjproject/trunk/pjsip-apps/src/samples/stateful_proxy.c	(revision 2407)
+++ pjproject/trunk/pjsip-apps/src/samples/stateful_proxy.c	(revision 2408)
@@ -556,5 +556,9 @@
 	     "");
 
-	fgets(line, sizeof(line), stdin);
+	if (fgets(line, sizeof(line), stdin) == NULL) {
+	    puts("EOF while reading stdin, will quit now..");
+	    global.quit_flag = PJ_TRUE;
+	    break;
+	}
 
 	if (line[0] == 'q') {
Index: pjproject/trunk/pjsip-apps/src/samples/stateless_proxy.c
===================================================================
--- pjproject/trunk/pjsip-apps/src/samples/stateless_proxy.c	(revision 2407)
+++ pjproject/trunk/pjsip-apps/src/samples/stateless_proxy.c	(revision 2408)
@@ -222,5 +222,9 @@
 	     "");
 
-	fgets(line, sizeof(line), stdin);
+	if (fgets(line, sizeof(line), stdin) == NULL) {
+	    puts("EOF while reading stdin, will quit now..");
+	    global.quit_flag = PJ_TRUE;
+	    break;
+	}
 
 	if (line[0] == 'q') {
Index: pjproject/trunk/pjsip-apps/src/samples/stereotest.c
===================================================================
--- pjproject/trunk/pjsip-apps/src/samples/stereotest.c	(revision 2407)
+++ pjproject/trunk/pjsip-apps/src/samples/stereotest.c	(revision 2408)
@@ -296,6 +296,7 @@
     puts("Press <ENTER> to stop and quit");
 
-    fgets(tmp, sizeof(tmp), stdin);
-
+    if (fgets(tmp, sizeof(tmp), stdin) == NULL) {
+	puts("EOF while reading stdin, will quit now..");
+    }
     
     /* Start deinitialization: */
Index: pjproject/trunk/pjsip-apps/src/samples/streamutil.c
===================================================================
--- pjproject/trunk/pjsip-apps/src/samples/streamutil.c	(revision 2407)
+++ pjproject/trunk/pjsip-apps/src/samples/streamutil.c	(revision 2408)
@@ -617,5 +617,8 @@
 	printf("Command: "); fflush(stdout);
 
-	fgets(tmp, sizeof(tmp), stdin);
+	if (fgets(tmp, sizeof(tmp), stdin) == NULL) {
+	    puts("EOF while reading stdin, will quit now..");
+	    break;
+	}
 
 	if (tmp[0] == 's')
Index: pjproject/trunk/pjsip-apps/src/samples/tonegen.c
===================================================================
--- pjproject/trunk/pjsip-apps/src/samples/tonegen.c	(revision 2407)
+++ pjproject/trunk/pjsip-apps/src/samples/tonegen.c	(revision 2408)
@@ -128,6 +128,9 @@
 
 	for (i=0; i<8000/SAMPLES_PER_FRAME; ++i) {
+	    int count;
 	    pjmedia_port_get_frame(port, &frm);
-	    fwrite(buf, SAMPLES_PER_FRAME, 2, f);
+	    count = fwrite(buf, SAMPLES_PER_FRAME, 2, f);
+	    if (count != 2)
+		break;
 	}
 
Index: pjproject/trunk/pjsip/src/test-pjsip/main.c
===================================================================
--- pjproject/trunk/pjsip/src/test-pjsip/main.c	(revision 2407)
+++ pjproject/trunk/pjsip/src/test-pjsip/main.c	(revision 2408)
@@ -83,5 +83,6 @@
 	char s[10];
 	printf("<Press ENTER to quit>\n"); fflush(stdout);
-	fgets(s, sizeof(s), stdin);
+	if (fgets(s, sizeof(s), stdin) == NULL)
+	    return retval;
     }
 
