15bebb993Sopenharmony_ci/* 25bebb993Sopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd. 35bebb993Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 45bebb993Sopenharmony_ci * you may not use this file except in compliance with the License. 55bebb993Sopenharmony_ci * You may obtain a copy of the License at 65bebb993Sopenharmony_ci * 75bebb993Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 85bebb993Sopenharmony_ci * 95bebb993Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 105bebb993Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 115bebb993Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 125bebb993Sopenharmony_ci * See the License for the specific language governing permissions and 135bebb993Sopenharmony_ci * limitations under the License. 145bebb993Sopenharmony_ci */ 155bebb993Sopenharmony_ci 165bebb993Sopenharmony_ci#include "utils.h" 175bebb993Sopenharmony_ci 185bebb993Sopenharmony_cinamespace OHOS { 195bebb993Sopenharmony_cinamespace CJSystemapi { 205bebb993Sopenharmony_ci 215bebb993Sopenharmony_ciunsigned int CommonFunc::ConvertCjFlags(unsigned int &flags) 225bebb993Sopenharmony_ci{ 235bebb993Sopenharmony_ci // default value is usrReadOnly 00 245bebb993Sopenharmony_ci unsigned int flagsABI = 0; 255bebb993Sopenharmony_ci flagsABI |= ((flags & USR_WRITE_ONLY) == USR_WRITE_ONLY) ? WRONLY : 0; 265bebb993Sopenharmony_ci flagsABI |= ((flags & USR_RDWR) == USR_RDWR) ? RDWR : 0; 275bebb993Sopenharmony_ci flagsABI |= ((flags & USR_CREATE) == USR_CREATE) ? CREATE : 0; 285bebb993Sopenharmony_ci flagsABI |= ((flags & USR_TRUNC) == USR_TRUNC) ? TRUNC : 0; 295bebb993Sopenharmony_ci flagsABI |= ((flags & USR_APPEND) == USR_APPEND) ? APPEND : 0; 305bebb993Sopenharmony_ci flagsABI |= ((flags & USR_NONBLOCK) == USR_NONBLOCK) ? NONBLOCK : 0; 315bebb993Sopenharmony_ci flagsABI |= ((flags & USR_DIRECTORY) == USR_DIRECTORY) ? DIRECTORY : 0; 325bebb993Sopenharmony_ci flagsABI |= ((flags & USR_NOFOLLOW) == USR_NOFOLLOW) ? NOFOLLOW : 0; 335bebb993Sopenharmony_ci flagsABI |= ((flags & USR_SYNC) == USR_SYNC) ? SYNC : 0; 345bebb993Sopenharmony_ci flags = flagsABI; 355bebb993Sopenharmony_ci return flagsABI; 365bebb993Sopenharmony_ci} 375bebb993Sopenharmony_ciusing namespace std; 385bebb993Sopenharmony_ci 395bebb993Sopenharmony_civoid CommonFunc::FsReqCleanup(uv_fs_t* req) 405bebb993Sopenharmony_ci{ 415bebb993Sopenharmony_ci if (req) { 425bebb993Sopenharmony_ci uv_fs_req_cleanup(req); 435bebb993Sopenharmony_ci delete req; 445bebb993Sopenharmony_ci req = nullptr; 455bebb993Sopenharmony_ci } 465bebb993Sopenharmony_ci} 475bebb993Sopenharmony_ci 485bebb993Sopenharmony_cistring CommonFunc::GetModeFromFlags(unsigned int flags) 495bebb993Sopenharmony_ci{ 505bebb993Sopenharmony_ci const string readMode = "r"; 515bebb993Sopenharmony_ci const string writeMode = "w"; 525bebb993Sopenharmony_ci const string appendMode = "a"; 535bebb993Sopenharmony_ci const string truncMode = "t"; 545bebb993Sopenharmony_ci string mode = readMode; 555bebb993Sopenharmony_ci mode += (((flags & O_RDWR) == O_RDWR) ? writeMode : ""); 565bebb993Sopenharmony_ci mode = (((flags & O_WRONLY) == O_WRONLY) ? writeMode : mode); 575bebb993Sopenharmony_ci if (mode != readMode) { 585bebb993Sopenharmony_ci mode += ((flags & O_TRUNC) ? truncMode : ""); 595bebb993Sopenharmony_ci mode += ((flags & O_APPEND) ? appendMode : ""); 605bebb993Sopenharmony_ci } 615bebb993Sopenharmony_ci return mode; 625bebb993Sopenharmony_ci} 635bebb993Sopenharmony_ci 645bebb993Sopenharmony_ci} 655bebb993Sopenharmony_ci}