RDK Documentation (Open Sourced RDK Components)
utils.cpp
1 /*
2  * If not stated otherwise in this file or this component's Licenses.txt file the
3  * following copyright and licenses apply:
4  *
5  * Copyright 2016 RDK Management
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18 */
19 /*
20  * utils.cpp
21  *
22  * Created on: Aug 25, 2014
23  * Author: tlemmons
24  */
25 
26 
27 /**
28 * @defgroup iarmmgrs
29 * @{
30 * @defgroup deviceUpdateMgr
31 * @{
32 **/
33 
34 
35 #include <assert.h>
36 #include <iostream>
37 #include <fstream>
38 #include <list>
39 #include <sys/stat.h>
40 #include <dirent.h>
41 #include <errno.h>
42 #include <vector>
43 #include <string>
44 #include <iostream>
45 #include <utils.h>
46 
47 using namespace std;
48 
49 bool _fileExists(string fileName)
50 {
51  struct stat buffer;
52  return (stat(fileName.c_str(), &buffer) == 0);
53 }
54 
55 bool _folderExists(string folderName)
56 {
57  struct stat buffer;
58  if (stat(folderName.c_str(), &buffer) == 0)
59  {
60  if (buffer.st_mode & __S_IFDIR != 0)
61  {
62  return true;
63  }
64  }
65  return false;
66 }
67 
68 vector<string> *getdir (string dir)
69 {
70  DIR *dp;
71  struct dirent *dirp;
72  vector<string> *files=new vector<string>();
73  if((dp = opendir(dir.c_str())) == NULL) {
74  return files;
75  }
76 
77  while ((dirp = readdir(dp)) != NULL) {
78  files->push_back(string(dirp->d_name));
79  }
80  closedir(dp);
81  return files;
82 }
83 
84 
85 
86 
87 
88 /** @} */
89 /** @} */