MCPcopy Index your code
hub / github.com/NetHack/NetHack / getmailstatus

Function getmailstatus

src/mail.c:96–141  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

94}
95
96void
97getmailstatus(void)
98{
99 if (mailbox) {
100 ; /* no need to repeat the setup */
101 } else if ((mailbox = nh_getenv("MAIL")) != 0) {
102 mailbox = dupstr(mailbox);
103#ifdef MAILPATH
104 } else {
105#ifdef AMS
106 struct passwd ppasswd;
107
108 (void) memcpy(&ppasswd, getpwuid(getuid()), sizeof (struct passwd));
109 if (ppasswd.pw_dir) {
110 /* note: 'sizeof "LITERAL"' includes +1 for terminating '\0' */
111 mailbox = (char *) alloc((unsigned) (strlen(ppasswd.pw_dir)
112 + sizeof AMS_MAILBOX));
113 Strcpy(mailbox, ppasswd.pw_dir);
114 Strcat(mailbox, AMS_MAILBOX);
115 }
116#else
117 const char *pw_name = getpwuid(getuid())->pw_name;
118
119 /* note: 'sizeof "LITERAL"' includes +1 for terminating '\0' */
120 mailbox = (char *) alloc((unsigned) (strlen(pw_name)
121 + sizeof MAILPATH));
122 Strcpy(mailbox, MAILPATH);
123 Strcat(mailbox, pw_name);
124#endif /* AMS */
125#endif /* MAILPATH */
126 }
127
128 debugpline3("mailbox=%c%s%c",
129 mailbox ? '\"' : '<',
130 mailbox ? mailbox : "null",
131 mailbox ? '\"' : '>');
132
133 if (mailbox && stat(mailbox, &omstat)) {
134#ifdef PERMANENT_MAILBOX
135 pline("Cannot get status of MAIL=\"%s\".", mailbox);
136 free_maildata(); /* set 'mailbox' to Null */
137#else
138 omstat.st_mtime = 0;
139#endif
140 }
141}
142#endif /* UNIX */
143
144/*

Callers 4

mainFunction · 0.85
libnhmain.cFile · 0.85
ckmailstatusFunction · 0.85
readmailFunction · 0.85

Calls 7

dupstrFunction · 0.85
getuidFunction · 0.85
free_maildataFunction · 0.85
nh_getenvFunction · 0.70
allocFunction · 0.70
statClass · 0.70
plineFunction · 0.70

Tested by

no test coverage detected