1 /* 2 * Copyright (c) 2020 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #include "ability_main.h" 17 18 #include <cerrno> 19 #include <climits> 20 21 #include "ability_thread.h" 22 #include "liteipc_pri.h" 23 #include "log.h" 24 25 namespace { 26 constexpr int HEX = 10; 27 } 28 AbilityMain(const char * token)29int AbilityMain(const char *token) 30 { 31 if (token == nullptr) { 32 return -1; 33 } 34 35 ResetLiteIpc(); 36 char *endPtr = nullptr; 37 errno = 0; 38 uint64_t tokenId = std::strtoull(token, &endPtr, HEX); 39 if ((errno == ERANGE && tokenId == ULLONG_MAX) || (errno != 0 && tokenId == 0) || 40 endPtr == nullptr || *endPtr != '\0') { 41 HILOG_ERROR(HILOG_MODULE_APP, "token is invalid"); 42 return -1; 43 } 44 45 OHOS::AbilityThread::ThreadMain(tokenId); 46 return 0; 47 } 48