summaryrefslogtreecommitdiff
path: root/src/qbiff.c
diff options
context:
space:
mode:
authorJannis Hoffmann <jannis@fehcom.de>2024-07-03 15:52:39 +0200
committerJannis Hoffmann <jannis@fehcom.de>2024-07-03 15:52:39 +0200
commita6a7d6ce079cabdaf2fa502b2e2cf15e5428ac6f (patch)
treeb88cc7a8457658d67e0321718556ac807f6bccf3 /src/qbiff.c
parent00be7622c428f279872f84569f098ce16150f8a8 (diff)
format files
Diffstat (limited to 'src/qbiff.c')
-rw-r--r--src/qbiff.c111
1 files changed, 63 insertions, 48 deletions
diff --git a/src/qbiff.c b/src/qbiff.c
index b9b55bf..186e524 100644
--- a/src/qbiff.c
+++ b/src/qbiff.c
@@ -1,28 +1,30 @@
-#include <sys/types.h>
#include <sys/stat.h>
+#include <sys/types.h>
#include <unistd.h>
+
#include "hasutmp.h"
#ifdef HASUTMP
-#include <utmp.h>
-#ifndef UTMP_FILE
-#ifdef _PATH_UTMP
-#define UTMP_FILE _PATH_UTMP
-#else
-#define UTMP_FILE "/etc/utmp"
-#endif
-#endif
+ #include <utmp.h>
+ #ifndef UTMP_FILE
+ #ifdef _PATH_UTMP
+ #define UTMP_FILE _PATH_UTMP
+ #else
+ #define UTMP_FILE "/etc/utmp"
+ #endif
+ #endif
#else
-#include <utmpx.h>
+ #include <utmpx.h>
#endif
-#include "stralloc.h"
#include "buffer.h"
-#include "open.h"
#include "byte.h"
+#include "env.h"
+#include "exit.h"
+#include "open.h"
#include "str.h"
+#include "stralloc.h"
+
#include "headerbody.h"
#include "hfield.h"
-#include "env.h"
-#include "exit.h"
buffer b;
#ifdef HASUTMP
@@ -46,23 +48,29 @@ stralloc text = {0};
void doit(char *s, int n)
{
- if (!stralloc_catb(&text,s,n)) _exit(0);
+ if (!stralloc_catb(&text, s, n)) _exit(0);
if (text.len > 78) text.len = 78;
}
-void dobody(stralloc *h) { doit(h->s,h->len); }
+void dobody(stralloc *h)
+{
+ doit(h->s, h->len);
+}
void doheader(stralloc *h)
{
int i;
- if (hfield_known(h->s,h->len) == H_SUBJECT) {
- i = hfield_skipname(h->s,h->len);
- doit(h->s + i,h->len - i);
+ if (hfield_known(h->s, h->len) == H_SUBJECT) {
+ i = hfield_skipname(h->s, h->len);
+ doit(h->s + i, h->len - i);
}
}
-void finishheader() { ; }
+void finishheader()
+{
+ ;
+}
int main()
{
@@ -83,58 +91,65 @@ int main()
if (str_len(user) > sizeof(ut->ut_user)) _exit(0);
#endif
- if (!stralloc_copys(&tofrom,"*** TO <")) _exit(0);
- if (!stralloc_cats(&tofrom,userext)) _exit(0);
- if (!stralloc_cats(&tofrom,"> FROM <")) _exit(0);
- if (!stralloc_cats(&tofrom,sender)) _exit(0);
- if (!stralloc_cats(&tofrom,">")) _exit(0);
+ if (!stralloc_copys(&tofrom, "*** TO <")) _exit(0);
+ if (!stralloc_cats(&tofrom, userext)) _exit(0);
+ if (!stralloc_cats(&tofrom, "> FROM <")) _exit(0);
+ if (!stralloc_cats(&tofrom, sender)) _exit(0);
+ if (!stralloc_cats(&tofrom, ">")) _exit(0);
for (i = 0; i < tofrom.len; ++i)
- if ((tofrom.s[i] < 32) || (tofrom.s[i] > 126))
- tofrom.s[i] = '_';
+ if ((tofrom.s[i] < 32) || (tofrom.s[i] > 126)) tofrom.s[i] = '_';
- if (!stralloc_copys(&text," ")) _exit(0);
- if (headerbody(buffer_0,doheader,finishheader,dobody) == -1) _exit(0);
+ if (!stralloc_copys(&text, " ")) _exit(0);
+ if (headerbody(buffer_0, doheader, finishheader, dobody) == -1) _exit(0);
for (i = 0; i < text.len; ++i)
- if ((text.s[i] < 32) || (text.s[i] > 126))
- text.s[i] = '/';
+ if ((text.s[i] < 32) || (text.s[i] > 126)) text.s[i] = '/';
- if (!stralloc_copys(&woof,"\015\n\007")) _exit(0);
- if (!stralloc_cat(&woof,&tofrom)) _exit(0);
- if (!stralloc_cats(&woof,"\015\n")) _exit(0);
- if (!stralloc_cat(&woof,&text)) _exit(0);
- if (!stralloc_cats(&woof,"\015\n")) _exit(0);
+ if (!stralloc_copys(&woof, "\015\n\007")) _exit(0);
+ if (!stralloc_cat(&woof, &tofrom)) _exit(0);
+ if (!stralloc_cats(&woof, "\015\n")) _exit(0);
+ if (!stralloc_cat(&woof, &text)) _exit(0);
+ if (!stralloc_cats(&woof, "\015\n")) _exit(0);
#ifdef HASUTMP
fdutmp = open_read(UTMP_FILE);
if (fdutmp == -1) _exit(0);
- buffer_init(&b,read,fdutmp,bufutmp,sizeof(bufutmp));
+ buffer_init(&b, read, fdutmp, bufutmp, sizeof(bufutmp));
- while (buffer_get(&b,&ut,sizeof(ut)) == sizeof(ut))
- if (!str_diffn(ut.ut_name,user,sizeof(ut.ut_name))) {
+ while (buffer_get(&b, &ut, sizeof(ut)) == sizeof(ut))
+ if (!str_diffn(ut.ut_name, user, sizeof(ut.ut_name))) {
#else
while ((ut = getutxent()) != 0)
- if (ut->ut_type == USER_PROCESS && !str_diffn(ut->ut_user,user,sizeof(ut->ut_user))) {
+ if (ut->ut_type == USER_PROCESS && !str_diffn(ut->ut_user, user, sizeof(ut->ut_user))) {
#endif
#ifdef HASUTMP
- byte_copy(line,sizeof(ut.ut_line),ut.ut_line);
+ byte_copy(line, sizeof(ut.ut_line), ut.ut_line);
line[sizeof(ut.ut_line)] = 0;
#else
- byte_copy(line,sizeof(ut->ut_line),ut->ut_line);
+ byte_copy(line, sizeof(ut->ut_line), ut->ut_line);
line[sizeof(ut->ut_line)] = 0;
#endif
if (line[0] == '/') continue;
if (!line[0]) continue;
- if (line[str_chr(line,'.')]) continue;
+ if (line[str_chr(line, '.')]) continue;
fdtty = open_append(line);
if (fdtty == -1) continue;
- if (fstat(fdtty,&st) == -1) { close(fdtty); continue; }
- if (!(st.st_mode & 0100)) { close(fdtty); continue; }
- if (st.st_uid != getuid()) { close(fdtty); continue; }
- buffer_init(&b,write,fdtty,buftty,sizeof(buftty));
- buffer_putflush(&b,woof.s,woof.len);
+ if (fstat(fdtty, &st) == -1) {
+ close(fdtty);
+ continue;
+ }
+ if (!(st.st_mode & 0100)) {
+ close(fdtty);
+ continue;
+ }
+ if (st.st_uid != getuid()) {
+ close(fdtty);
+ continue;
+ }
+ buffer_init(&b, write, fdtty, buftty, sizeof(buftty));
+ buffer_putflush(&b, woof.s, woof.len);
close(fdtty);
}
_exit(0);