• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 <sys/types.h>
17 #include <sys/stat.h>
18 #include <fcntl.h>
19 #include <unistd.h>
20 #include <iostream>
21 #include <fstream>
22 #include "string_ex.h"
23 #include "media_errors.h"
24 #include "directory_ex.h"
25 #include "aw_common.h"
26 
27 
28 using namespace std;
29 using namespace OHOS;
30 using namespace Media;
31 using namespace PlayerTestParam;
32 
33 namespace OHOS {
34 namespace Media {
35 namespace PlayerTestParam {
WriteDataToFile(const std::string & path,const std::uint8_t * data,std::size_t size)36 int32_t WriteDataToFile(const std::string &path, const std::uint8_t *data, std::size_t size)
37 {
38     FILE *file = nullptr;
39     file = fopen(path.c_str(), "w+");
40     if (file == nullptr) {
41         return -1;
42     }
43     if (fwrite(data, 1, size, file) != size) {
44         (void)fclose(file);
45         return -1;
46     }
47     (void)fclose(file);
48     return 0;
49 }
50 
ProduceRandomNumberCrypt(void)51 int32_t ProduceRandomNumberCrypt(void)
52 {
53     int32_t r = 0;
54     int fd = open("/dev/random", O_RDONLY);
55     if (fd > 0) {
56         read(fd, &r, sizeof(int32_t));
57     }
58     close(fd);
59     return r;
60 }
61 }
62 }
63 }