* @return This function returns the file handle on success,
or INVALID_FILE on failure
*/
-mtp_uint32 _util_file_open(const mtp_char *filename, file_mode_t mode,
+FILE* _util_file_open(const mtp_char *filename, file_mode_t mode,
mtp_int32 *error)
{
#ifdef __USE_STDIO__
default:
ERR("Invalid mode : %d\n", mode);
*error = EINVAL;
- return INVALID_FILE;
+ return NULL;
}
fhandle = fopen(filename, fmode);
ERR("File open Fail:mode[0x%x], errno [%d]\n", mode, errno);
ERR_SECURE("filename[%s]\n", filename);
*error = errno;
- return INVALID_FILE;
+ return NULL;
}
fcntl(fileno(fhandle), F_SETFL, O_NOATIME);
- return (mtp_uint32)fhandle;
+ return fhandle;
#else /* __USE_STDIO__ */
default:
ERR("Invalid mode : %d\n", mode);
*error = EINVAL;
- return INVALID_FILE;
+ return NULL;
}
if (perm)
ERR("File open Fail:mode[0x%x], errno [%d]\n", mode, errno);
ERR_SECURE("filename[%s]\n", filename);
*error = errno;
- return INVALID_FILE;
+ return NULL;
}
- return (mtp_uint32)fhandle;
+ return fhandle;
#endif /* __USE_STDIO__ */
}
* @param[out] preadcount Will store the actual num bytes read.
* @return None
*/
-void _util_file_read(mtp_uint32 fhandle, void *bufptr, mtp_uint32 size,
+void _util_file_read(FILE* fhandle, void *bufptr, mtp_uint32 size,
mtp_uint32 *read_count)
{
mtp_uint32 bytes_read = 0;
#ifdef __USE_STDIO__
- bytes_read = fread_unlocked(bufptr, sizeof(mtp_char), size, (FILE *)fhandle);
+ bytes_read = fread_unlocked(bufptr, sizeof(mtp_char), size, fhandle);
#else /* __USE_STDIO__ */
bytes_read = read(fhandle, bufptr, size);
#endif /* __USE_STDIO__ */
* @return This function returns num bytes written.
*/
-mtp_uint32 _util_file_write(mtp_uint32 fhandle, void *bufptr, mtp_uint32 size)
+mtp_uint32 _util_file_write(FILE* fhandle, void *bufptr, mtp_uint32 size)
{
mtp_uint32 bytes_written = 0;
#ifdef __USE_STDIO__
- bytes_written = fwrite_unlocked(bufptr, sizeof(mtp_char), size, (FILE *)fhandle);
+ bytes_written = fwrite_unlocked(bufptr, sizeof(mtp_char), size, fhandle);
#else /* __USE_STDIO__ */
mtp_int32 ret = 0;
* @param[in] handle Specifies the handle of file to close.
* @return 0 in case of success or EOF on failure.
*/
-mtp_int32 _util_file_close(mtp_uint32 fhandle)
+mtp_int32 _util_file_close(FILE* fhandle)
{
#ifdef __USE_STDIO__
- return fclose((FILE *)fhandle);
+ return fclose(fhandle);
#else /* __USE_STDIO__ */
return close(fhandle);
#endif /* __USE_STDIO__ */
* @param[in] whence Specifies the setting value
* @return Returns TRUE in case of success or FALSE on Failure.
*/
-mtp_bool _util_file_seek(mtp_uint32 handle, off_t offset, mtp_int32 whence)
+mtp_bool _util_file_seek(FILE* handle, off_t offset, mtp_int32 whence)
{
mtp_int64 ret_val = 0;
#ifdef __USE_STDIO__
- ret_val = fseek((FILE *)handle, offset, whence);
+ ret_val = fseek(handle, offset, whence);
#else /* __USE_STDIO__ */
ret_val = lseek(handle, offset, whence);
if (ret_val > 0)
}
if (MTP_ERROR_OBJECT_WRITE_PROTECTED == ret) {
DBG("Folder[%s] contains read-only files,hence\
- folder is not deleted\n",pathname);
+ folder is not deleted\n", pathname);
/* Read the next entry */
goto DONE;
}
(S_IWGRP & entryinfo.st_mode) ||
(S_IWOTH & entryinfo.st_mode))) {
ret = MTP_ERROR_OBJECT_WRITE_PROTECTED;
- DBG("File [%s] is readOnly:Deletion Fail\n",pathname);
+ DBG("File [%s] is readOnly:Deletion Fail\n", pathname);
goto DONE;
}
}
switch (stat_buf.st_mode & S_IFMT) {
case S_IFREG:
dir_info->type = MTP_FILE_TYPE;
- if (!(stat_buf.st_mode & (S_IWUSR | S_IWGRP | S_IWOTH))) {
+ if (!(stat_buf.st_mode & (S_IWUSR | S_IWGRP | S_IWOTH)))
dir_info->attrs.attribute |= MTP_FILE_ATTR_MODE_READ_ONLY;
- }
break;
case S_IFDIR:
return TRUE;
}
-void _util_count_num_lines(mtp_uint32 fhandle, mtp_uint32 *num_lines)
+void _util_count_num_lines(FILE* fhandle, mtp_uint32 *num_lines)
{
- if (fhandle == INVALID_FILE)
+ if (fhandle == NULL)
return;
mtp_uint32 line_count = 0;
}
#ifdef __USE_STDIO__
- while((read_bytes = getline(&buffer,
- &line_max_length, (FILE *)fhandle)) != -1) {
+ while ((read_bytes = getline(&buffer,
+ (size_t *)&line_max_length, fhandle)) != -1) {
if (read_bytes > MTP_MAX_PATHNAME_SIZE + 1)
continue;
line_count++;
mtp_uint32 prev_pos = -1;
mtp_uint32 new_pos;
mtp_uint32 filename_len = 0;
- while((read_bytes = read(fhandle, buffer, LINUX_MAX_PATHNAME_LENGTH)) > 0) {
+ while ((read_bytes = read(fhandle, buffer, LINUX_MAX_PATHNAME_LENGTH)) > 0) {
for (ii = 0; ii < read_bytes; ii++) {
if (buffer[ii] != '\n')
continue;
continue;
line_count++;
}
- if (buffer[read_bytes - 1] != '\n') {
+ if (buffer[read_bytes - 1] != '\n')
_util_file_seek(fhandle, prev_pos + 1 - read_bytes, SEEK_CUR);
- }
+
prev_pos = -1;
}
#endif /* __USE_STDIO__ */
}
void _util_fill_guid_array(void *guidarray, mtp_uint32 start_index,
- mtp_uint32 fhandle, mtp_uint32 size)
+ FILE* fhandle, mtp_uint32 size)
{
ptp_array_t *pguidarray = NULL;
mtp_uint32 *guidptr = NULL;
}
#ifdef __USE_STDIO__
- while ((len = getline(&buffer, &line_max_length, (FILE *)fhandle)) != -1 &&
+ while ((len = getline(&buffer, (size_t *)&line_max_length, fhandle)) != -1 &&
(num_lines - start_index) <= size) {
if (len > MTP_MAX_PATHNAME_SIZE + 1)
continue;
mtp_char file_name[MTP_MAX_PATHNAME_SIZE + 1];
mtp_int32 read_bytes;
- while ((read_bytes = read(fHandle, buffer,
+ while ((read_bytes = read(fhandle, buffer,
LINUX_MAX_PATHNAME_LENGTH)) > 0 &&
(num_lines - start_index) <= size) {
pguidarray->num_elements += sizeof(mtp_uint32);
}
- if (buffer[read_bytes - 1] != '\n') {
+ if (buffer[read_bytes - 1] != '\n')
_util_file_seek(fhandle, prev_pos + 1 - read_bytes, SEEK_CUR);
- }
+
prev_pos = -1;
}
#endif /* __USE_STDIO__ */
fp = fopen(MTP_LOG_FILE, "a+");
}
- if (fp == NULL) {
+ if (fp == NULL)
return;
- }
written_bytes += fprintf(fp, "%s ", __FILE__);
va_start(ap, fmt);