Rimetto quello che avevo levato
[gapil.git] / sources / SetTermAttr.c
diff --git a/sources/SetTermAttr.c b/sources/SetTermAttr.c
new file mode 100644 (file)
index 0000000..96aef88
--- /dev/null
@@ -0,0 +1,70 @@
+/* SetTermAttr.c
+ * 
+ * Copyright (C) 2002 Simone Piccardi
+ * 
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or (at
+ * your option) any later version.
+ * 
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+/****************************************************************
+ *
+ * Routine SetTermAttr
+ * Routine to set a local attribute for a terminal
+ *
+ * Author: Simone Piccardi
+ * Jun. 2001
+ *
+ * $Id: SetTermAttr.c,v 1.3 2003/05/02 09:55:14 piccardi Exp $ 
+ *
+ ****************************************************************/
+#include <unistd.h>
+#include <termios.h>
+#include <errno.h>
+
+int SetTermAttr(int fd, tcflag_t flag) 
+{
+    struct termios values;
+    int res;
+
+    res = tcgetattr (desc, &values);
+    if (res) {
+       perror("Cannot get attributes");
+       return res;
+    }
+    values.c_lflag |= flag;
+    res = tcsetattr (desc, TCSANOW, &values);
+    if (res) {
+       perror("Cannot set attributes");
+       return res;
+    }
+    return 0;
+}
+int UnSetTermAttr(int fd, tcflag_t flag) 
+{
+    struct termios values;
+    int res;
+
+    res = tcgetattr (desc, &values);
+    if (res) {
+       perror("Cannot get attributes");
+       return res;
+    }
+    values.c_lflag &= (~flag);
+    res = tcsetattr (desc, TCSANOW, &values);
+    if (res) {
+       perror("Cannot set attributes");
+       return res;
+    }
+    return 0;
+}
+