blob: af8f826800e067898ddbcd14da599e2a63222114 [file] [log] [blame] [raw]
/* Common utmpx implementation
* Copyright 2015-2023 Rivoreo
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*/
#include "utmpx.h"
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
void updwtmpx(const char *wtmpx_file, const struct utmpx *utx) {
int fd = open(wtmpx_file, O_WRONLY | O_APPEND);
if(fd == -1) return;
size_t written = 0;
do {
int s = write(fd, (const char *)utx + written, sizeof *utx - written);
if(s < 0) {
if(errno == EINTR) continue;
break;
}
written += s;
} while(written < sizeof *utx);
close(fd);
}