}
memset(c->cifs_stats[i], 0, CIFS_ST_SIZE);
}
- strncpy(c->name, name, MAX_NAME_LEN);
- c->name[MAX_NAME_LEN - 1] = '\0';
+ strncpy(c->name, name, sizeof(c->name));
+ c->name[sizeof(c->name) - 1] = '\0';
c->exist = TRUE;
c->next = cs;
else {
start = 1;
}
- strncpy(cifs_name, name_tmp, MAX_NAME_LEN);
- cifs_name[MAX_NAME_LEN - 1] = '\0';
+ strncpy(cifs_name, name_tmp, sizeof(cifs_name));
+ cifs_name[sizeof(cifs_name) - 1] = '\0';
memset(&scifs, 0, CIFS_ST_SIZE);
}
else {
if (!strncmp(name, pretty, FILENAME_MAX)) {
/* We have found pretty name for current persistent one */
- strncpy(wwn_name, drd->d_name, FILENAME_MAX);
- wwn_name[FILENAME_MAX - 1] = '\0';
+ strncpy(wwn_name, drd->d_name, sizeof(wwn_name));
+ wwn_name[sizeof(wwn_name) - 1] = '\0';
/* Try to extract WWN */
if (!extract_wwnid(wwn_name, wwn, part_nr)) {
if (!strncmp(resolved_name, "/dev/", 5)) {
i = 5;
}
- strncpy(out, resolved_name + i, MAX_FILE_LEN);
- out[MAX_FILE_LEN - 1] = '\0';
+ strncpy(out, resolved_name + i, sizeof(out));
+ out[sizeof(out) - 1] = '\0';
/* Some devices may have a slash in their name (eg. cciss/c0d0...) */
while ((slash = strchr(out, '/'))) {
{
static char path[PATH_MAX];
- snprintf(path, PATH_MAX, "%s/%s",
+ snprintf(path, sizeof(path), "%s/%s",
get_persistent_type_dir(persistent_name_type), name);
if (access(path, F_OK)) {
if (!strncmp(name, pretty, FILENAME_MAX)) {
/* We have found pretty name for current persistent one */
- strncpy(persist_name, persist_names[i], FILENAME_MAX);
- persist_name[FILENAME_MAX - 1] = '\0';
+ strncpy(persist_name, persist_names[i], sizeof(persist_name));
+ persist_name[sizeof(persist_name) - 1] = '\0';
break;
}
}
while ((drd = readdir(dir)) != NULL) {
if (!strncmp(drd->d_name, "cpu", 3) && isdigit(drd->d_name[3])) {
- snprintf(line, MAX_PF_NAME, "%s/%s", SYSFS_DEVCPU, drd->d_name);
- line[MAX_PF_NAME - 1] = '\0';
+ snprintf(line, sizeof(line), "%s/%s", SYSFS_DEVCPU, drd->d_name);
+ line[sizeof(line) - 1] = '\0';
if (stat(line, &buf) < 0)
continue;
if (S_ISDIR(buf.st_mode)) {
if ((fp = fopen(IOCONF, "r")) == NULL) {
if ((fp = fopen(LOCAL_IOCONF, "r")) == NULL)
return 0;
- strncpy(ioconf_name, LOCAL_IOCONF, 64);
+ strncpy(ioconf_name, LOCAL_IOCONF, sizeof(ioconf_name));
}
else {
- strncpy(ioconf_name, IOCONF, 64);
+ strncpy(ioconf_name, IOCONF, sizeof(ioconf_name));
}
- ioconf_name[63] = '\0';
+ ioconf_name[sizeof(ioconf_name) - 1] = '\0';
/* Init ioc_refnr array */
memset(ioc_refnr, 0, sizeof(ioc_refnr));
- while (fgets(buf, IOC_LINESIZ - 1, fp)) {
+ while (fgets(buf, sizeof(buf) - 1, fp)) {
if ((*buf == '#') || (*buf == '\n'))
continue;
/* Is this an extension record? */
if (p->blkp->ext && (p->blkp->ext_minor == minor)) {
- strncpy(name, p->blkp->ext_name, IOC_DEVLEN);
- name[IOC_DEVLEN - 1] = '\0';
+ strncpy(name, p->blkp->ext_name, sizeof(name));
+ name[sizeof(name) - 1] = '\0';
return (name);
}
while ((dp = readdir(dm_dir)) != NULL) {
/* For each file in DEVMAP_DIR */
- snprintf(filen, MAX_FILE_LEN, "%s/%s", DEVMAP_DIR, dp->d_name);
- filen[MAX_FILE_LEN - 1] = '\0';
+ snprintf(filen, sizeof(filen), "%s/%s", DEVMAP_DIR, dp->d_name);
+ filen[sizeof(filen) - 1] = '\0';
if (__stat(filen, &aux) == 0) {
/* Get its minor and major numbers */
dm_minor = minor(aux.st_rdev);
if ((dm_minor == minor) && (dm_major == major)) {
- strncpy(name, dp->d_name, MAX_NAME_LEN);
- name[MAX_NAME_LEN - 1] = '\0';
+ strncpy(name, dp->d_name, sizeof(name));
+ name[sizeof(name) - 1] = '\0';
dm_name = name;
break;
}
if (argv[opt++][0] == '+') {
flags |= I_D_ALL_DIR;
}
- strncpy(alt_dir, argv[opt++], MAX_FILE_LEN);
- alt_dir[MAX_FILE_LEN - 1] = '\0';
+ strncpy(alt_dir, argv[opt++], sizeof(alt_dir));
+ alt_dir[sizeof(alt_dir) - 1] = '\0';
if (!check_dir(alt_dir)) {
usage(argv[0]);
}
if (!argv[++opt]) {
usage(argv[0]);
}
- if (strnlen(argv[opt], MAX_FILE_LEN) >= MAX_FILE_LEN - 1) {
+ if (strnlen(argv[opt], sizeof(persistent_name_type)) >= sizeof(persistent_name_type) - 1) {
usage(argv[0]);
}
- strncpy(persistent_name_type, argv[opt], MAX_FILE_LEN - 1);
- persistent_name_type[MAX_FILE_LEN - 1] = '\0';
+ strncpy(persistent_name_type, argv[opt], sizeof(persistent_name_type) - 1);
+ persistent_name_type[sizeof(persistent_name_type) - 1] = '\0';
strtolower(persistent_name_type);
/* Check that this is a valid type of persistent device name */
if (!get_persistent_type_dir(persistent_name_type)) {
cpu_per_node[0] = nr_cpus;
for (cpu = 0; cpu < nr_cpus; cpu++) {
- snprintf(line, MAX_PF_NAME, "%s/cpu%d", SYSFS_DEVCPU, cpu);
- line[MAX_PF_NAME - 1] = '\0';
+ snprintf(line, sizeof(line), "%s/cpu%d", SYSFS_DEVCPU, cpu);
+ line[sizeof(line) - 1] = '\0';
/* Open relevant /sys directory */
if ((dir = opendir(line)) == NULL)
cpu_topo_i = cpu_topo + cpu;
/* Read current CPU's socket number */
- snprintf(filename, MAX_PF_NAME, "%s/cpu%d/%s", SYSFS_DEVCPU, cpu, PHYS_PACK_ID);
- filename[MAX_PF_NAME - 1] = '\0';
+ snprintf(filename, sizeof(filename), "%s/cpu%d/%s", SYSFS_DEVCPU, cpu, PHYS_PACK_ID);
+ filename[sizeof(filename) - 1] = '\0';
if ((fp = fopen(filename, "r")) != NULL) {
rc = fscanf(fp, "%d", &cpu_topo_i->phys_package_id);
}
/* Read current CPU's logical core id number */
- snprintf(filename, MAX_PF_NAME, "%s/cpu%d/%s", SYSFS_DEVCPU, cpu, THREAD_SBL_LST);
- filename[MAX_PF_NAME - 1] = '\0';
+ snprintf(filename, sizeof(filename), "%s/cpu%d/%s", SYSFS_DEVCPU, cpu, THREAD_SBL_LST);
+ filename[sizeof(filename) - 1] = '\0';
if ((fp = fopen(filename, "r")) != NULL) {
rc = fscanf(fp, "%d", &cpu_topo_i->logical_core_id);
memset(line, 0, MAX_CMDLINE_LEN);
- len = fread(line, 1, MAX_CMDLINE_LEN - 1, fp);
+ len = fread(line, 1, sizeof(line) - 1, fp);
fclose(fp);
if (len) {
line[i] = ' ';
}
}
- strncpy(plist->cmdline, line, MAX_CMDLINE_LEN - 1);
- plist->cmdline[MAX_CMDLINE_LEN - 1] = '\0';
+ strncpy(plist->cmdline, line, sizeof(plist->cmdline) - 1);
+ plist->cmdline[sizeof(plist->cmdline) - 1] = '\0';
}
else {
/* proc/.../cmdline was empty */
strcpy(cur_time[!curr], "# Time ");
}
else if (PRINT_SEC_EPOCH(pidflag)) {
- snprintf(cur_time[!curr], TIMESTAMP_LEN, "%-11ld", mktime(&ps_tstamp[!curr]));
- cur_time[!curr][TIMESTAMP_LEN - 1] = '\0';
+ snprintf(cur_time[!curr], sizeof(cur_time[!curr]), "%-11ld", mktime(&ps_tstamp[!curr]));
+ cur_time[!curr][sizeof(cur_time[!curr]) - 1] = '\0';
}
else if (is_iso_time_fmt()) {
strftime(cur_time[!curr], sizeof(cur_time[!curr]), "%H:%M:%S", &ps_tstamp[!curr]);
/* Get current timestamp */
if (PRINT_SEC_EPOCH(pidflag)) {
- snprintf(cur_time[curr], TIMESTAMP_LEN, "%-11ld", mktime(&ps_tstamp[curr]));
- cur_time[curr][TIMESTAMP_LEN - 1] = '\0';
+ snprintf(cur_time[curr], sizeof(cur_time[curr]), "%-11ld", mktime(&ps_tstamp[curr]));
+ cur_time[curr][sizeof(cur_time[curr]) - 1] = '\0';
}
else if (is_iso_time_fmt()) {
strftime(cur_time[curr], sizeof(cur_time[curr]), "%H:%M:%S", &ps_tstamp[curr]);
if (!argv[++opt]) {
usage(argv[0]);
}
- strncpy(commstr, argv[opt++], MAX_COMM_LEN);
- commstr[MAX_COMM_LEN - 1] = '\0';
+ strncpy(commstr, argv[opt++], sizeof(commstr));
+ commstr[sizeof(commstr) - 1] = '\0';
pidflag |= P_F_COMMSTR;
if (!strlen(commstr)) {
usage(argv[0]);
if (!argv[++opt]) {
usage(argv[0]);
}
- strncpy(procstr, argv[opt++], MAX_COMM_LEN);
- procstr[MAX_COMM_LEN - 1] = '\0';
+ strncpy(procstr, argv[opt++], sizeof(procstr));
+ procstr[sizeof(procstr) - 1] = '\0';
pidflag |= P_F_PROCSTR;
if (!strlen(procstr)) {
usage(argv[0]);
pidflag |= P_D_USERNAME;
if (argv[++opt] && (argv[opt][0] != '-') &&
(strspn(argv[opt], DIGITS) != strlen(argv[opt]))) {
- strncpy(userstr, argv[opt++], MAX_USER_LEN);
- userstr[MAX_USER_LEN - 1] = '\0';
+ strncpy(userstr, argv[opt++], sizeof(userstr));
+ userstr[sizeof(userstr) - 1] = '\0';
pidflag |= P_F_USERSTR;
if (!strlen(userstr)) {
usage(argv[0]);
int i = -1, j;
int p = pos;
- strncpy(hline, a->hdr_line, HEADER_LINE_LEN - 1);
- hline[HEADER_LINE_LEN - 1] = '\0';
+ strncpy(hline, a->hdr_line, sizeof(hline) - 1);
+ hline[sizeof(hline) - 1] = '\0';
for (hl = strtok(hline, "|"); hl && (pos > 0); hl = strtok(NULL, "|"), pos--);
if (!hl)
/* Bad @pos arg given to function */
int i, j = 0;
if (hdr_line) {
- strncpy(hline, hdr_line, HEADER_LINE_LEN - 1);
- hline[HEADER_LINE_LEN - 1] = '\0';
+ strncpy(hline, hdr_line, sizeof(hline) - 1);
+ hline[sizeof(hline) - 1] = '\0';
idx = 0;
for (hl = strtok(hline, "|"); hl && (pos > 0); hl = strtok(NULL, "|"), pos--);
j = strcspn(hl, "&");
*(hl + j) = ';';
}
- strncpy(field, hl, HEADER_LINE_LEN);
- field[HEADER_LINE_LEN - 1] = '\0';
+ strncpy(field, hl, sizeof(field));
+ field[sizeof(field) - 1] = '\0';
}
/* Display current field */
}
st_net_dev_i = st_net_dev + dev_read++;
- strncpy(iface, line, MINIMUM(pos, MAX_IFACE_LEN - 1));
- iface[MINIMUM(pos, MAX_IFACE_LEN - 1)] = '\0';
+ strncpy(iface, line, MINIMUM(pos, sizeof(iface) - 1));
+ iface[MINIMUM(pos, sizeof(iface) - 1)] = '\0';
sscanf(iface, "%s", st_net_dev_i->interface); /* Skip heading spaces */
sscanf(line + pos + 1, "%llu %llu %*u %*u %*u %*u %llu %llu %llu %llu "
"%*u %*u %*u %*u %*u %llu",
}
st_net_edev_i = st_net_edev + dev_read++;
- strncpy(iface, line, MINIMUM(pos, MAX_IFACE_LEN - 1));
- iface[MINIMUM(pos, MAX_IFACE_LEN - 1)] = '\0';
+ strncpy(iface, line, MINIMUM(pos, sizeof(iface) - 1));
+ iface[MINIMUM(pos, sizeof(iface) - 1)] = '\0';
sscanf(iface, "%s", st_net_edev_i->interface); /* Skip heading spaces */
sscanf(line + pos + 1, "%*u %*u %llu %llu %llu %llu %*u %*u %*u %*u "
"%llu %llu %llu %llu %llu",
st_filesystem_i->f_bavail = (unsigned long long) buf.f_bavail * (unsigned long long) buf.f_frsize;
st_filesystem_i->f_files = (unsigned long long) buf.f_files;
st_filesystem_i->f_ffree = (unsigned long long) buf.f_ffree;
- strncpy(st_filesystem_i->fs_name, fs_name, MAX_FS_LEN);
- st_filesystem_i->fs_name[MAX_FS_LEN - 1] = '\0';
- strncpy(st_filesystem_i->mountp, mountp, MAX_FS_LEN);
- st_filesystem_i->mountp[MAX_FS_LEN - 1] = '\0';
+ strncpy(st_filesystem_i->fs_name, fs_name, sizeof(st_filesystem_i->fs_name));
+ st_filesystem_i->fs_name[sizeof(st_filesystem_i->fs_name) - 1] = '\0';
+ strncpy(st_filesystem_i->mountp, mountp, sizeof(st_filesystem_i->mountp));
+ st_filesystem_i->mountp[sizeof(st_filesystem_i->mountp) - 1] = '\0';
}
}
st_fc_i->f_txframes = tx_frames;
st_fc_i->f_rxwords = rx_words;
st_fc_i->f_txwords = tx_words;
- memcpy(st_fc_i->fchost_name, drd->d_name, MAX_FCH_LEN);
- st_fc_i->fchost_name[MAX_FCH_LEN - 1] = '\0';
+ memcpy(st_fc_i->fchost_name, drd->d_name, sizeof(st_fc_i->fchost_name));
+ st_fc_i->fchost_name[sizeof(st_fc_i->fchost_name) - 1] = '\0';
}
}
*sa_name = 0;
/* Look for saYYYYMMDD */
- snprintf(filename, MAX_FILE_LEN,
+ snprintf(filename, sizeof(filename),
"%s/sa%04d%02d%02d", sa_dir,
rectime->tm_year + 1900,
rectime->tm_mon + 1,
rectime->tm_mday);
- filename[MAX_FILE_LEN - 1] = '\0';
+ filename[sizeof(filename) - 1] = '\0';
if (stat(filename, &sb) < 0)
/* Cannot find or access saYYYYMMDD, so use saDD */
nsec = sb.st_mtim.tv_nsec;
/* Look for saDD */
- snprintf(filename, MAX_FILE_LEN,
+ snprintf(filename, sizeof(filename),
"%s/sa%02d", sa_dir,
rectime->tm_mday);
- filename[MAX_FILE_LEN - 1] = '\0';
+ filename[sizeof(filename) - 1] = '\0';
if (stat(filename, &sb) < 0) {
/* Cannot find or access saDD, so use saYYYYMMDD */
/* Set directory where daily data files will be saved */
if (datafile[0]) {
- strncpy(sa_dir, datafile, MAX_FILE_LEN);
+ strncpy(sa_dir, datafile, sizeof(sa_dir));
}
else {
- strncpy(sa_dir, SA_DIR, MAX_FILE_LEN);
+ strncpy(sa_dir, SA_DIR, sizeof(sa_dir));
}
- sa_dir[MAX_FILE_LEN - 1] = '\0';
+ sa_dir[sizeof(sa_dir) - 1] = '\0';
get_time(&rectime, d_off);
if (sa_name < 0) {
return 0;
}
- if (strnlen(argv[*opt], MAX_FILE_LEN) >= MAX_FILE_LEN - 1)
+ if (strnlen(argv[*opt], sizeof(persistent_name_type)) >= sizeof(persistent_name_type) - 1)
return 1;
- strncpy(persistent_name_type, argv[*opt], MAX_FILE_LEN - 1);
- persistent_name_type[MAX_FILE_LEN - 1] = '\0';
+ strncpy(persistent_name_type, argv[*opt], sizeof(persistent_name_type) - 1);
+ persistent_name_type[sizeof(persistent_name_type) - 1] = '\0';
strtolower(persistent_name_type);
if (!get_persistent_type_dir(persistent_name_type)) {
fprintf(stderr, _("Invalid type of persistent device name\n"));
file_hdr->sa_day = f_hdr_2171->sa_day;
file_hdr->sa_month = f_hdr_2171->sa_month;
file_hdr->sa_sizeof_long = f_hdr_2171->sa_sizeof_long;
- strncpy(file_hdr->sa_sysname, f_hdr_2171->sa_sysname, UTSNAME_LEN);
- file_hdr->sa_sysname[UTSNAME_LEN - 1] = '\0';
- strncpy(file_hdr->sa_nodename, f_hdr_2171->sa_nodename, UTSNAME_LEN);
- file_hdr->sa_nodename[UTSNAME_LEN - 1] = '\0';
- strncpy(file_hdr->sa_release, f_hdr_2171->sa_release, UTSNAME_LEN);
- file_hdr->sa_release[UTSNAME_LEN - 1] = '\0';
- strncpy(file_hdr->sa_machine, f_hdr_2171->sa_machine, UTSNAME_LEN);
- file_hdr->sa_machine[UTSNAME_LEN - 1] = '\0';
+ strncpy(file_hdr->sa_sysname, f_hdr_2171->sa_sysname, sizeof(file_hdr->sa_sysname));
+ file_hdr->sa_sysname[sizeof(file_hdr->sa_sysname) - 1] = '\0';
+ strncpy(file_hdr->sa_nodename, f_hdr_2171->sa_nodename, sizeof(file_hdr->sa_nodename));
+ file_hdr->sa_nodename[sizeof(file_hdr->sa_nodename) - 1] = '\0';
+ strncpy(file_hdr->sa_release, f_hdr_2171->sa_release, sizeof(file_hdr->sa_release));
+ file_hdr->sa_release[sizeof(file_hdr->sa_release) - 1] = '\0';
+ strncpy(file_hdr->sa_machine, f_hdr_2171->sa_machine, sizeof(file_hdr->sa_machine));
+ file_hdr->sa_machine[sizeof(file_hdr->sa_machine) - 1] = '\0';
}
else if (previous_format == FORMAT_MAGIC_2173) {
sndc->tx_compressed = moveto_long_long(&sndp->tx_compressed, endian_mismatch, arch_64);
sndc->multicast = moveto_long_long(&sndp->multicast, endian_mismatch, arch_64);
sndc->speed = 0; /* New field */
- strncpy(sndc->interface, sndp->interface, MAX_IFACE_LEN);
- sndc->interface[MAX_IFACE_LEN - 1] = '\0';
+ strncpy(sndc->interface, sndp->interface, sizeof(sndc->interface));
+ sndc->interface[sizeof(sndc->interface) - 1] = '\0';
sndc->duplex = '\0'; /* New field */
}
}
sndc->tx_compressed = sndp->tx_compressed;
sndc->multicast = sndp->multicast;
sndc->speed = 0; /* New field */
- strncpy(sndc->interface, sndp->interface, MAX_IFACE_LEN);
- sndc->interface[MAX_IFACE_LEN - 1] = '\0';
+ strncpy(sndc->interface, sndp->interface, sizeof(sndc->interface));
+ sndc->interface[sizeof(sndc->interface) - 1] = '\0';
sndc->duplex = '\0'; /* New field */
}
}
sndc->tx_compressed = sndp->tx_compressed;
sndc->multicast = sndp->multicast;
sndc->speed = sndp->speed;
- strncpy(sndc->interface, sndp->interface, MAX_IFACE_LEN);
- sndc->interface[MAX_IFACE_LEN - 1] = '\0';
+ strncpy(sndc->interface, sndp->interface, sizeof(sndc->interface));
+ sndc->interface[sizeof(sndc->interface) - 1] = '\0';
sndc->duplex = sndp->duplex;
}
}
snedc->tx_fifo_errors = moveto_long_long(&snedp->tx_fifo_errors, endian_mismatch, arch_64);
snedc->rx_frame_errors = moveto_long_long(&snedp->rx_frame_errors, endian_mismatch, arch_64);
snedc->tx_carrier_errors = moveto_long_long(&snedp->tx_carrier_errors, endian_mismatch, arch_64);
- strncpy(snedc->interface, snedp->interface, MAX_IFACE_LEN);
- snedc->interface[MAX_IFACE_LEN - 1] = '\0';
+ strncpy(snedc->interface, snedp->interface, sizeof(snedc->interface));
+ snedc->interface[sizeof(snedc->interface) - 1] = '\0';
}
}
else {
snedc->tx_fifo_errors = snedp->tx_fifo_errors;
snedc->rx_frame_errors = snedp->rx_frame_errors;
snedc->tx_carrier_errors = snedp->tx_carrier_errors;
- strncpy(snedc->interface, snedp->interface, MAX_IFACE_LEN);
- snedc->interface[MAX_IFACE_LEN - 1] = '\0';
+ strncpy(snedc->interface, snedp->interface, sizeof(snedc->interface));
+ snedc->interface[sizeof(snedc->interface) - 1] = '\0';
}
}
}
sfc->f_bavail = sfp->f_bavail;
sfc->f_files = sfp->f_files;
sfc->f_ffree = sfp->f_ffree;
- strncpy(sfc->fs_name, sfp->fs_name, MAX_FS_LEN);
- sfc->fs_name[MAX_FS_LEN - 1] = '\0';
+ strncpy(sfc->fs_name, sfp->fs_name, sizeof(sfc->fs_name));
+ sfc->fs_name[sizeof(sfc->fs_name) - 1] = '\0';
if (st_size <= STATS_FILESYSTEM_8A_1_SIZE) {
/* mountp didn't exist with older versions */
sfc->mountp[0] = '\0';
}
else {
- strncpy(sfc->mountp, sfp->mountp, MAX_FS_LEN);
- sfc->mountp[MAX_FS_LEN - 1] = '\0';
+ strncpy(sfc->mountp, sfp->mountp, sizeof(sfc->mountp));
+ sfc->mountp[sizeof(sfc->mountp) - 1] = '\0';
}
}
}
char file_comment[MAX_COMMENT_LEN];
/* Read the COMMENT record */
- sa_fread(fd, file_comment, MAX_COMMENT_LEN, HARD_SIZE, UEOF_STOP);
- file_comment[MAX_COMMENT_LEN - 1] = '\0';
+ sa_fread(fd, file_comment, sizeof(file_comment), HARD_SIZE, UEOF_STOP);
+ file_comment[sizeof(file_comment) - 1] = '\0';
/* Then write it. No changes at this time */
- if (write_all(stdfd, file_comment, MAX_COMMENT_LEN) != MAX_COMMENT_LEN) {
+ if (write_all(stdfd, file_comment, sizeof(file_comment)) != sizeof(file_comment)) {
fprintf(stderr, "\nwrite: %s\n", strerror(errno));
return -1;
}
/* Get system name, release number, hostname and machine architecture */
__uname(&header);
- strncpy(file_hdr.sa_sysname, header.sysname, UTSNAME_LEN);
- file_hdr.sa_sysname[UTSNAME_LEN - 1] = '\0';
- strncpy(file_hdr.sa_nodename, header.nodename, UTSNAME_LEN);
- file_hdr.sa_nodename[UTSNAME_LEN - 1] = '\0';
- strncpy(file_hdr.sa_release, header.release, UTSNAME_LEN);
- file_hdr.sa_release[UTSNAME_LEN - 1] = '\0';
- strncpy(file_hdr.sa_machine, header.machine, UTSNAME_LEN);
- file_hdr.sa_machine[UTSNAME_LEN - 1] = '\0';
+ strncpy(file_hdr.sa_sysname, header.sysname, sizeof(file_hdr.sa_sysname));
+ file_hdr.sa_sysname[sizeof(file_hdr.sa_sysname) - 1] = '\0';
+ strncpy(file_hdr.sa_nodename, header.nodename, sizeof(file_hdr.sa_nodename));
+ file_hdr.sa_nodename[sizeof(file_hdr.sa_nodename) - 1] = '\0';
+ strncpy(file_hdr.sa_release, header.release, sizeof(file_hdr.sa_release));
+ file_hdr.sa_release[sizeof(file_hdr.sa_release) - 1] = '\0';
+ strncpy(file_hdr.sa_machine, header.machine, sizeof(file_hdr.sa_machine));
+ file_hdr.sa_machine[sizeof(file_hdr.sa_machine) - 1] = '\0';
/* Get timezone value and save it */
tzset();
/* Rotate activity file if necessary */
if (WANT_SA_ROTAT(flags)) {
/* The user specified '-' as the filename to use */
- strncpy(new_ofile, sa_dir, MAX_FILE_LEN - 1);
- new_ofile[MAX_FILE_LEN - 1] = '\0';
+ strncpy(new_ofile, sa_dir, sizeof(new_ofile) - 1);
+ new_ofile[sizeof(new_ofile) - 1] = '\0';
set_default_file(new_ofile, 0, USE_SA_YYYYMMDD(flags));
if (strcmp(ofile, new_ofile)) {
if (!argv[++opt]) {
usage(argv[0]);
}
- strncpy(comment, argv[opt], MAX_COMMENT_LEN);
- comment[MAX_COMMENT_LEN - 1] = '\0';
+ strncpy(comment, argv[opt], sizeof(comment));
+ comment[sizeof(comment) - 1] = '\0';
if (!strlen(comment)) {
usage(argv[0]);
}
}
else {
/* Write data to file */
- strncpy(ofile, argv[opt], MAX_FILE_LEN);
- ofile[MAX_FILE_LEN - 1] = '\0';
+ strncpy(ofile, argv[opt], sizeof(ofile));
+ ofile[sizeof(ofile) - 1] = '\0';
}
}
}
else {
msk = 1;
- strncpy(hline, act[i]->hdr_line, HEADER_LINE_LEN - 1);
- hline[HEADER_LINE_LEN - 1] = '\0';
+ strncpy(hline, act[i]->hdr_line, sizeof(hline) - 1);
+ hline[sizeof(hline) - 1] = '\0';
for (hl = strtok(hline, "|"); hl; hl = strtok(NULL, "|"), msk <<= 1) {
if ((hl != NULL) && ((act[i]->opt_flags & 0xff) & msk)) {
if (strchr(hl, '&')) {
}
else if (!strncmp(t, K_PCPARCHIVE, strlen(K_PCPARCHIVE))) {
v = t + strlen(K_PCPARCHIVE);
- strncpy(pcparchive, v, MAX_FILE_LEN);
- pcparchive[MAX_FILE_LEN - 1] = '\0';
+ strncpy(pcparchive, v, sizeof(pcparchive));
+ pcparchive[sizeof(pcparchive) - 1] = '\0';
}
else if (!strncmp(t, K_HZ, strlen(K_HZ))) {
v = t + strlen(K_HZ);
usage(argv[0]);
}
/* Write data to file */
- strncpy(dfile, argv[opt++], MAX_FILE_LEN);
- dfile[MAX_FILE_LEN - 1] = '\0';
+ strncpy(dfile, argv[opt++], sizeof(dfile));
+ dfile[sizeof(dfile) - 1] = '\0';
/* Check if this is an alternate directory for sa files */
check_alt_sa_dir(dfile, 0, -1);
}
/* Interval value in 1/100th of a second */
itv = get_interval(record_hdr[2].uptime_cs, record_hdr[curr].uptime_cs);
- strncpy(timestamp[curr], _("Average:"), TIMESTAMP_LEN);
- timestamp[curr][TIMESTAMP_LEN - 1] = '\0';
- memcpy(timestamp[!curr], timestamp[curr], TIMESTAMP_LEN);
+ strncpy(timestamp[curr], _("Average:"), sizeof(timestamp[curr]));
+ timestamp[curr][sizeof(timestamp[curr]) - 1] = '\0';
+ memcpy(timestamp[!curr], timestamp[curr], sizeof(timestamp[!curr]));
/* Test stdout */
TEST_STDOUT(STDOUT_FILENO);
/* Save stats to a file */
if ((argv[++opt]) && strncmp(argv[opt], "-", 1) &&
(strspn(argv[opt], DIGITS) != strlen(argv[opt]))) {
- strncpy(to_file, argv[opt++], MAX_FILE_LEN);
- to_file[MAX_FILE_LEN - 1] = '\0';
+ strncpy(to_file, argv[opt++], sizeof(to_file));
+ to_file[sizeof(to_file) - 1] = '\0';
}
else {
strcpy(to_file, "-");
/* Read stats from a file */
if ((argv[++opt]) && strncmp(argv[opt], "-", 1) &&
(strspn(argv[opt], DIGITS) != strlen(argv[opt]))) {
- strncpy(from_file, argv[opt++], MAX_FILE_LEN);
- from_file[MAX_FILE_LEN - 1] = '\0';
+ strncpy(from_file, argv[opt++], sizeof(from_file));
+ from_file[sizeof(from_file) - 1] = '\0';
/* Check if this is an alternate directory for sa files */
check_alt_sa_dir(from_file, day_offset, -1);
}
static double *spmin, *spmax;
static char **out;
static int *outsize;
- char item_name[8];
+ char item_name[16];
int i;
if (action & F_BEGIN) {
static double *spmin, *spmax;
static char **out;
static int *outsize;
- char item_name[MAX_SENSORS_DEV_LEN + 8];
+ char item_name[MAX_SENSORS_DEV_LEN + 16];
int i;
if (action & F_BEGIN) {
spc = (struct stats_pwr_fan *) ((char *) a->buf[curr] + i * a->msize);
- snprintf(item_name, MAX_SENSORS_DEV_LEN + 8, "%d: %s", i + 1, spc->device);
- item_name[MAX_SENSORS_DEV_LEN + 7] = '\0';
+ snprintf(item_name, sizeof(item_name), "%d: %s", i + 1, spc->device);
+ item_name[sizeof(item_name) - 1] = '\0';
if (draw_activity_graphs(a->g_nr, g_type,
title, g_title, item_name, group,
static double *spmin, *spmax;
static char **out;
static int *outsize;
- char item_name[MAX_SENSORS_DEV_LEN + 8];
+ char item_name[MAX_SENSORS_DEV_LEN + 16];
int i;
double tval;
spc = (struct stats_pwr_temp *) ((char *) a->buf[curr] + i * a->msize);
- snprintf(item_name, MAX_SENSORS_DEV_LEN + 8, "%d: %s", i + 1, spc->device);
- item_name[MAX_SENSORS_DEV_LEN + 7] = '\0';
+ snprintf(item_name, sizeof(item_name), "%d: %s", i + 1, spc->device);
+ item_name[sizeof(item_name) - 1] = '\0';
if (draw_activity_graphs(a->g_nr, g_type,
title, g_title, item_name, group,
static double *spmin, *spmax;
static char **out;
static int *outsize;
- char item_name[MAX_SENSORS_DEV_LEN + 8];
+ char item_name[MAX_SENSORS_DEV_LEN + 16];
int i;
double tval;
spc = (struct stats_pwr_in *) ((char *) a->buf[curr] + i * a->msize);
- snprintf(item_name, MAX_SENSORS_DEV_LEN + 8, "%d: %s", i + 1, spc->device);
- item_name[MAX_SENSORS_DEV_LEN + 7] = '\0';
+ snprintf(item_name, sizeof(item_name), "%d: %s", i + 1, spc->device);
+ item_name[sizeof(item_name) - 1] = '\0';
if (draw_activity_graphs(a->g_nr, g_type,
title, g_title, item_name, group,