[hackers] [st] st now runs on Linux, OpenBSD and FreeBSD. || Aurélien Aptel

From: <hg_AT_suckless.org>
Date: Fri, 27 Aug 2010 23:18:25 +0000 (UTC)

changeset: 98:e4b926c50b0b
tag: tip
user: Aurélien Aptel <aurelien.aptel_AT_gmail.com>
date: Sat Aug 28 03:18:22 2010 +0200
files: Makefile config.mk st.c
description:
st now runs on Linux, OpenBSD and FreeBSD.

diff -r dfef8c8727d9 -r e4b926c50b0b Makefile
--- a/Makefile Fri Aug 27 13:53:27 2010 +0200
+++ b/Makefile Sat Aug 28 03:18:22 2010 +0200
@@ -10,6 +10,7 @@
 
 options:
         @echo st build options:
+ @echo "SYSTEM = ${SYSTEM}"
         @echo "CFLAGS = ${CFLAGS}"
         @echo "LDFLAGS = ${LDFLAGS}"
         @echo "CC = ${CC}"
@@ -31,7 +32,7 @@
 dist: clean
         @echo creating dist tarball
         @mkdir -p st-${VERSION}
- @cp -R LICENSE Makefile README config.mk st.h ${SRC} st-${VERSION}
+ @cp -R LICENSE Makefile README config.mk config.h st.info ${SRC} st-${VERSION}
         @tar -cf st-${VERSION}.tar st-${VERSION}
         @gzip st-${VERSION}.tar
         @rm -rf st-${VERSION}
@@ -41,7 +42,7 @@
         @mkdir -p ${DESTDIR}${PREFIX}/bin
         @cp -f st ${DESTDIR}${PREFIX}/bin
         @chmod 755 ${DESTDIR}${PREFIX}/bin/st
- @tic st.info
+ @tic -s st.info
 
 uninstall:
         @echo removing executable file from ${DESTDIR}${PREFIX}/bin
diff -r dfef8c8727d9 -r e4b926c50b0b config.mk
--- a/config.mk Fri Aug 27 13:53:27 2010 +0200
+++ b/config.mk Sat Aug 28 03:18:22 2010 +0200
@@ -12,16 +12,17 @@
 
 # includes and libs
 INCS = -I. -I/usr/include -I${X11INC}
-LIBS = -L/usr/lib -lc -L${X11LIB} -lX11
+LIBS = -L/usr/lib -lc -L${X11LIB} -lX11 -lutil
+
+# uncomment your system #
+#SYSTEM = -DLINUX
+#SYSTEM = -DOPENBSD
+#SYSTEM = -DFREEBSD
 
 # flags
-CPPFLAGS = -DVERSION=\"${VERSION}\"
+CPPFLAGS = -DVERSION=\"${VERSION}\" ${SYSTEM}
 CFLAGS = -std=c99 -pedantic -Wall -Os ${INCS} ${CPPFLAGS}
 LDFLAGS = -s ${LIBS}
 
-# Solaris
-#CFLAGS = -fast ${INCS} -DVERSION=\"${VERSION}\"
-#LDFLAGS = ${LIBS}
-
 # compiler and linker
 CC = cc
diff -r dfef8c8727d9 -r e4b926c50b0b st.c
--- a/st.c Fri Aug 27 13:53:27 2010 +0200
+++ b/st.c Sat Aug 28 03:18:22 2010 +0200
@@ -20,6 +20,14 @@
 #include <X11/keysym.h>
 #include <X11/Xutil.h>
 
+#if defined(LINUX)
+ #include <pty.h>
+#elif defined(OPENBSD)
+ #include <util.h>
+#elif defined(FREEBSD)
+ #include <libutil.h>
+#endif
+
 /* Arbitrary sizes */
 #define ESC_TITLE_SIZ 256
 #define ESC_BUF_SIZ 256
@@ -242,19 +250,12 @@
 void
 ttynew(void) {
         int m, s;
- char *pts;
+
+ /* seems to work fine on linux, openbsd and freebsd */
+ struct winsize w = {term.row, term.col, 0, 0};
+ if(openpty(&m, &s, NULL, NULL, &w) < 0)
+ die("openpty failed: %s\n", SERRNO);
 
- if((m = posix_openpt(O_RDWR | O_NOCTTY)) < 0)
- die("openpt failed: %s\n", SERRNO);
- if(grantpt(m) < 0)
- die("grantpt failed: %s\n", SERRNO);
- if(unlockpt(m) < 0)
- die("unlockpt failed: %s\n", SERRNO);
- if(!(pts = ptsname(m)))
- die("ptsname failed: %s\n", SERRNO);
- if((s = open(pts, O_RDWR | O_NOCTTY)) < 0)
- die("Couldn't open slave: %s\n", SERRNO);
- fcntl(s, F_SETFL, O_NDELAY);
         switch(pid = fork()) {
         case -1:
                 die("fork failed\n");
Received on Sat Aug 28 2010 - 01:18:25 CEST

This archive was generated by hypermail 2.2.0 : Sat Aug 28 2010 - 01:24:05 CEST