1 /* 2 * 3 * Copyright 2010 Samsung Electronics S.LSI Co. LTD 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18 /* 19 * @file SEC_OSAL_ETC.c 20 * @brief 21 * @author SeungBeom Kim (sbcrux.kim (at) samsung.com) 22 * @version 1.0 23 * @history 24 * 2010.7.15 : Create 25 */ 26 27 #include <stdio.h> 28 #include <stdlib.h> 29 #include <string.h> 30 31 #include "SEC_OSAL_Memory.h" 32 #include "SEC_OSAL_ETC.h" 33 34 35 #ifndef HAVE_GETLINE 36 ssize_t getline(char **ppLine, size_t *pLen, FILE *pStream) 37 { 38 char *pCurrentPointer = NULL; 39 size_t const chunk = 512; 40 41 size_t defaultBufferSize = chunk + 1; 42 size_t retSize = 0; 43 44 if (*ppLine == NULL) { 45 *ppLine = (char *)malloc(defaultBufferSize); 46 if (*ppLine == NULL) { 47 retSize = -1; 48 goto EXIT; 49 } 50 *pLen = defaultBufferSize; 51 } 52 else { 53 if (*pLen < defaultBufferSize) { 54 *ppLine = (char *)realloc(*ppLine, defaultBufferSize); 55 if (*ppLine == NULL) { 56 retSize = -1; 57 goto EXIT; 58 } 59 *pLen = defaultBufferSize; 60 } 61 } 62 63 while (1) { 64 size_t i; 65 size_t j = 0; 66 size_t readByte = 0; 67 68 pCurrentPointer = *ppLine + readByte; 69 70 i = fread(pCurrentPointer, 1, chunk, pStream); 71 if (i < chunk && ferror(pStream)) { 72 retSize = -1; 73 goto EXIT; 74 } 75 while (j < i) { 76 ++j; 77 if (*pCurrentPointer++ == (char)'\n') { 78 *pCurrentPointer = '\0'; 79 if (j != i) { 80 if (fseek(pStream, j - i, SEEK_CUR)) { 81 retSize = -1; 82 goto EXIT; 83 } 84 if (feof(pStream)) 85 clearerr(pStream); 86 } 87 readByte += j; 88 retSize = readByte; 89 goto EXIT; 90 } 91 } 92 93 readByte += j; 94 if (feof(pStream)) { 95 if (readByte) { 96 retSize = readByte; 97 goto EXIT; 98 } 99 if (!i) { 100 retSize = -1; 101 goto EXIT; 102 } 103 } 104 105 i = ((readByte + (chunk * 2)) / chunk) * chunk; 106 if (i != *pLen) { 107 *ppLine = (char *)realloc(*ppLine, i); 108 if (*ppLine == NULL) { 109 retSize = -1; 110 goto EXIT; 111 } 112 *pLen = i; 113 } 114 } 115 116 EXIT: 117 return retSize; 118 } 119 #endif /* HAVE_GETLINE */ 120 121 OMX_PTR SEC_OSAL_Strcpy(OMX_PTR dest, OMX_PTR src) 122 { 123 return strcpy(dest, src); 124 } 125 126 OMX_PTR SEC_OSAL_Strncpy(OMX_PTR dest, OMX_PTR src, size_t num) 127 { 128 return strncpy(dest, src, num); 129 } 130 131 OMX_S32 SEC_OSAL_Strcmp(OMX_PTR str1, OMX_PTR str2) 132 { 133 return strcmp(str1, str2); 134 } 135 136 OMX_PTR SEC_OSAL_Strcat(OMX_PTR dest, OMX_PTR src) 137 { 138 return strcat(dest, src); 139 } 140 141 size_t SEC_OSAL_Strlen(const char *str) 142 { 143 return strlen(str); 144 } 145