Coverage Report

Created: 2026-10-17 06:38

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/barebox/commands/setenv.c
Line
Count
Source
1
// SPDX-License-Identifier: GPL-2.0-only
2
// SPDX-FileCopyrightText: © 2007 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix
3
4
#include <common.h>
5
#include <command.h>
6
#include <errno.h>
7
#include <environment.h>
8
#include <complete.h>
9
10
static int do_setenv(int argc, char *argv[])
11
0
{
12
0
  char *val;
13
0
  int ret;
14
15
0
  if (argc < 2)
16
0
    return COMMAND_ERROR_USAGE;
17
18
0
  val = parse_assignment(argv[1]);
19
0
  if (val)
20
0
    argv[2] = val;
21
22
0
  if (argv[2])
23
0
    ret = setenv(argv[1], argv[2]);
24
0
  else
25
0
    ret = unsetenv(argv[1]);
26
27
0
  return ret ? COMMAND_ERROR : COMMAND_SUCCESS;
28
0
}
29
30
BAREBOX_CMD_HELP_START(setenv)
31
BAREBOX_CMD_HELP_TEXT("Set environment variable NAME to VALUE.")
32
BAREBOX_CMD_HELP_TEXT("If VALUE is omitted, then the variable is deleted.")
33
BAREBOX_CMD_HELP_END
34
35
BAREBOX_CMD_START(setenv)
36
  .cmd    = do_setenv,
37
  BAREBOX_CMD_DESC("set environment variable")
38
  BAREBOX_CMD_OPTS("NAME [VALUE]")
39
  BAREBOX_CMD_GROUP(CMD_GRP_ENV)
40
  BAREBOX_CMD_COMPLETE(env_param_noeval_complete)
41
  BAREBOX_CMD_HELP(cmd_setenv_help)
42
BAREBOX_CMD_END