Annotation of solidite/utils/tty.c, revision 1.1
1.1 ! user 1: /* Copyright (c) 2026 The Solidite Developers
! 2: *
! 3: * This program is free software: you can redistribute it and/or modify it under
! 4: * the terms of the GNU Affero General Public License as published by the Free
! 5: * Software Foundation, either version 3 of the License, or (at your option)
! 6: * any later version.
! 7: *
! 8: * This program is distributed in the hope that it will be useful, but WITHOUT
! 9: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
! 10: * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
! 11: * details.
! 12: *
! 13: * You should have received a copy of the GNU Affero General Public License
! 14: * along with this program. If not, see <https://www.gnu.org/licenses/>. */
! 15:
! 16: #include <stdlib.h>
! 17: #include <string.h>
! 18: #include <unistd.h>
! 19:
! 20: int main(void) {
! 21: const char *TTY_NAME = ttyname(STDIN_FILENO);
! 22: if (TTY_NAME == NULL) {
! 23: const char MESSAGE[] = "not a tty\n";
! 24: (void)write(STDOUT_FILENO, MESSAGE, strlen(MESSAGE));
! 25: return 1;
! 26: }
! 27:
! 28: char *output = (char*)malloc(strlen(TTY_NAME) + 1);
! 29: strcpy(output, TTY_NAME);
! 30: output[strlen(TTY_NAME)] = '\n';
! 31: (void)write(STDOUT_FILENO, output, strlen(output));
! 32: return 0;
! 33: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>