1f9f848faSopenharmony_ci/*
2f9f848faSopenharmony_ci * Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
3f9f848faSopenharmony_ci * Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
4f9f848faSopenharmony_ci *
5f9f848faSopenharmony_ci * Redistribution and use in source and binary forms, with or without modification,
6f9f848faSopenharmony_ci * are permitted provided that the following conditions are met:
7f9f848faSopenharmony_ci *
8f9f848faSopenharmony_ci * 1. Redistributions of source code must retain the above copyright notice, this list of
9f9f848faSopenharmony_ci *    conditions and the following disclaimer.
10f9f848faSopenharmony_ci *
11f9f848faSopenharmony_ci * 2. Redistributions in binary form must reproduce the above copyright notice, this list
12f9f848faSopenharmony_ci *    of conditions and the following disclaimer in the documentation and/or other materials
13f9f848faSopenharmony_ci *    provided with the distribution.
14f9f848faSopenharmony_ci *
15f9f848faSopenharmony_ci * 3. Neither the name of the copyright holder nor the names of its contributors may be used
16f9f848faSopenharmony_ci *    to endorse or promote products derived from this software without specific prior written
17f9f848faSopenharmony_ci *    permission.
18f9f848faSopenharmony_ci *
19f9f848faSopenharmony_ci * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20f9f848faSopenharmony_ci * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
21f9f848faSopenharmony_ci * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22f9f848faSopenharmony_ci * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
23f9f848faSopenharmony_ci * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24f9f848faSopenharmony_ci * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25f9f848faSopenharmony_ci * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
26f9f848faSopenharmony_ci * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
27f9f848faSopenharmony_ci * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
28f9f848faSopenharmony_ci * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
29f9f848faSopenharmony_ci * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30f9f848faSopenharmony_ci */
31f9f848faSopenharmony_ci
32f9f848faSopenharmony_ci#include "sys/prctl.h"
33f9f848faSopenharmony_ci#include "los_task_pri.h"
34f9f848faSopenharmony_ci
35f9f848faSopenharmony_ciint prctl(int option, ...)
36f9f848faSopenharmony_ci{
37f9f848faSopenharmony_ci    unsigned long name;
38f9f848faSopenharmony_ci    va_list ap;
39f9f848faSopenharmony_ci    errno_t err;
40f9f848faSopenharmony_ci
41f9f848faSopenharmony_ci    va_start(ap, option);
42f9f848faSopenharmony_ci    if (option != PR_SET_NAME) {
43f9f848faSopenharmony_ci        PRINT_ERR("%s: %d, no support option : 0x%x\n", __FUNCTION__, __LINE__, option);
44f9f848faSopenharmony_ci        err = EOPNOTSUPP;
45f9f848faSopenharmony_ci        goto ERROR;
46f9f848faSopenharmony_ci    }
47f9f848faSopenharmony_ci
48f9f848faSopenharmony_ci    name = va_arg(ap, unsigned long);
49f9f848faSopenharmony_ci    err = OsSetTaskName(OsCurrTaskGet(), (const char *)name, TRUE);
50f9f848faSopenharmony_ci    if (err != LOS_OK) {
51f9f848faSopenharmony_ci        goto ERROR;
52f9f848faSopenharmony_ci    }
53f9f848faSopenharmony_ci
54f9f848faSopenharmony_ci    va_end(ap);
55f9f848faSopenharmony_ci    return ENOERR;
56f9f848faSopenharmony_ci
57f9f848faSopenharmony_ciERROR:
58f9f848faSopenharmony_ci    va_end(ap);
59f9f848faSopenharmony_ci    return -err;
60f9f848faSopenharmony_ci}
61f9f848faSopenharmony_ci
62