changeset: 71:be5c51a4f016
tag: tip
user: pancake <pancake_AT_nopcode.org>
date: Mon Aug 30 22:53:00 2010 +0200
files: t/calc.c
description:
check popen return value in calc example
diff -r f809cb86d832 -r be5c51a4f016 t/calc.c
--- a/t/calc.c Fri Aug 27 20:32:23 2010 +0200
+++ b/t/calc.c Mon Aug 30 22:53:00 2010 +0200
@@ -6,6 +6,8 @@
static char buffer[256];
static void button(SwkEvent *e) {
+ FILE *pd;
+ static char buffer2[sizeof(buffer)+32];
if(e->type==EClick) {
int key = *e->box->text;
switch(key) {
@@ -17,15 +19,13 @@
buffer[--bufferi] = 0;
break;
case '=':
- {
- FILE *pd;
- static char buffer2[sizeof(buffer)+32];
snprintf(buffer2, sizeof(buffer2), "echo '%s' | bc -q", buffer);
pd = popen(buffer2, "r");
- fgets(buffer, sizeof(buffer), pd);
- bufferi = strlen(buffer)-1;
- buffer[bufferi] = 0;
- pclose(pd);
+ if(pd) {
+ fgets(buffer, sizeof(buffer), pd);
+ bufferi = strlen(buffer)-1;
+ buffer[bufferi] = 0;
+ pclose(pd);
}
break;
default:
Received on Mon Aug 30 2010 - 22:56:17 CEST
This archive was generated by hypermail 2.2.0 : Mon Aug 30 2010 - 23:00:07 CEST