MCPcopy Create free account
hub / github.com/NetHack/NetHack / read_simplemail

Function read_simplemail

src/mail.c:588–680  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

586#if defined(SIMPLE_MAIL) || defined(SERVER_ADMIN_MSG)
587
588void
589read_simplemail(const char *mbox, boolean adminmsg)
590{
591 FILE *mb = fopen(mbox, "r");
592 char curline[128], *msg;
593 boolean seen_one_already = FALSE;
594#ifdef SIMPLE_MAIL
595 struct flock fl = { 0 };
596#endif
597
598 if (!mb)
599 goto bail;
600
601#ifdef SIMPLE_MAIL
602 fl.l_type = F_RDLCK;
603 fl.l_whence = SEEK_SET;
604 fl.l_start = 0;
605 fl.l_len = 0;
606 errno = 0;
607#endif
608
609 /* Allow this call to block. */
610 if (!adminmsg
611#ifdef SIMPLE_MAIL
612 && fcntl(fileno(mb), F_SETLKW, &fl) == -1
613#endif
614 )
615 goto bail;
616
617 while (fgets(curline, 128, mb) != NULL) {
618 const char *endpunct;
619 int msglen;
620
621 if (!adminmsg) {
622#ifdef SIMPLE_MAIL
623 fl.l_type = F_UNLCK;
624 fcntl(fileno(mb), F_UNLCK, &fl);
625#endif
626 There("is a%s message on this scroll.",
627 seen_one_already ? "nother" : "");
628 }
629 msg = strchr(curline, ':');
630
631 /* if incorrectly formatted, or message is empty (':' and '\n' take
632 up 2 chars, so must have at least 3 to be nonempty), give up */
633 if (!msg || (msglen = (int) strlen(msg)) < 3)
634 goto bail;
635
636 *msg = '\0';
637 msg++, msglen--;
638 msg[msglen - 1] = '\0'; /* kill newline */
639
640 /* supply ending punctuation only if the message doesn't have any */
641 endpunct = "";
642 if (!strchr(".!?", msg[msglen - 2]))
643 endpunct = ".";
644
645 if (adminmsg) {

Callers 2

ck_server_admin_msgFunction · 0.85
readmailFunction · 0.85

Calls 6

fgetsFunction · 0.85
ThereFunction · 0.85
urgent_plineFunction · 0.85
fcloseFunction · 0.85
unlinkFunction · 0.85
plineFunction · 0.70

Tested by

no test coverage detected