Fix auto data call for ril v2
Change-Id: I753b1c8ac7bcbeabd316734b54b4e79224537dea
diff --git a/mbtk/libmbtk_lib/common/mbtk_file.c b/mbtk/libmbtk_lib/common/mbtk_file.c
index 44f3954..235ccd2 100755
--- a/mbtk/libmbtk_lib/common/mbtk_file.c
+++ b/mbtk/libmbtk_lib/common/mbtk_file.c
@@ -126,3 +126,73 @@
}
return result;
}
+
+/*===========================================================================
+FUNCTION file_link()
+
+DESCRIPTION:
+ Create soft link.
+
+PARAMETERS:
+ oldpath [IN]: Local original file,it may not exist.
+ newpath [IN]: Soft link file. If the file exists, it will be replaced.
+
+RETURN VALUE:
+ Return 0 if success,other for error.
+
+===========================================================================*/
+int file_link(const void* oldpath, const void* newpath)
+{
+ if(oldpath == NULL || newpath == NULL) {
+ LOGE("File not be NULL.");
+ return -1;
+ }
+
+ struct stat file_stat;
+ int ret = lstat((const char*)newpath, &file_stat);
+ if (ret) {
+ if (errno != ENOENT) {
+ LOGE("lstat(%s) fail:%d", (char*)newpath, errno);
+ return -1;
+ }
+
+ // Link file not exist, Create link file directly.
+ } else {
+ if (S_ISLNK(file_stat.st_mode)) {
+ // The file is a symbolic link
+ char buf[1024] = {0};
+ ssize_t len = readlink((char*)newpath, buf, sizeof(buf));
+ if (len == -1) {
+ LOGE("Error reading the link file, errno - %d", errno);
+ return -1;
+ }
+ buf[len] = '\0';
+ LOGD("Link target is: %s", buf);
+ if(strcmp(buf, (const char*)oldpath) == 0) {
+ LOGD("The link target is same,do nothing.");
+ return 0;
+ } else {
+ ret = unlink((const char*)newpath);
+ if(ret) {
+ LOGE("unlink(%s) fail:%d", (char*)newpath, errno);
+ return -1;
+ }
+
+ // Delete link file success.
+ }
+ } else {
+ LOGE("%s exist,but no link file.", (char*)newpath);
+ return -1;
+ }
+ }
+
+ // Start create link file.
+ ret = symlink((const char*)oldpath, (const char*)newpath);
+ if(ret){
+ LOGE("symlink(%s->%s) fail:%d", (char*)newpath, (const char*)newpath, errno);
+ return -1;
+ } else {
+ LOGE("symlink(%s->%s) success.", (char*)newpath, (const char*)newpath);
+ return 0;
+ }
+}