windir.cpp
Upload User: dangjiwu
Upload Date: 2013-07-19
Package Size: 42019k
Code Size: 5k
Category:

Symbian

Development Platform:

Visual C++

  1. /* ***** BEGIN LICENSE BLOCK *****
  2.  * Source last modified: $Id: windir.cpp,v 1.5.36.3 2004/07/09 01:44:27 hubbe Exp $
  3.  * 
  4.  * Portions Copyright (c) 1995-2004 RealNetworks, Inc. All Rights Reserved.
  5.  * 
  6.  * The contents of this file, and the files included with this file,
  7.  * are subject to the current version of the RealNetworks Public
  8.  * Source License (the "RPSL") available at
  9.  * http://www.helixcommunity.org/content/rpsl unless you have licensed
  10.  * the file under the current version of the RealNetworks Community
  11.  * Source License (the "RCSL") available at
  12.  * http://www.helixcommunity.org/content/rcsl, in which case the RCSL
  13.  * will apply. You may also obtain the license terms directly from
  14.  * RealNetworks.  You may not use this file except in compliance with
  15.  * the RPSL or, if you have a valid RCSL with RealNetworks applicable
  16.  * to this file, the RCSL.  Please see the applicable RPSL or RCSL for
  17.  * the rights, obligations and limitations governing use of the
  18.  * contents of the file.
  19.  * 
  20.  * Alternatively, the contents of this file may be used under the
  21.  * terms of the GNU General Public License Version 2 or later (the
  22.  * "GPL") in which case the provisions of the GPL are applicable
  23.  * instead of those above. If you wish to allow use of your version of
  24.  * this file only under the terms of the GPL, and not to allow others
  25.  * to use your version of this file under the terms of either the RPSL
  26.  * or RCSL, indicate your decision by deleting the provisions above
  27.  * and replace them with the notice and other provisions required by
  28.  * the GPL. If you do not delete the provisions above, a recipient may
  29.  * use your version of this file under the terms of any one of the
  30.  * RPSL, the RCSL or the GPL.
  31.  * 
  32.  * This file is part of the Helix DNA Technology. RealNetworks is the
  33.  * developer of the Original Code and owns the copyrights in the
  34.  * portions it created.
  35.  * 
  36.  * This file, and the files included with this file, is distributed
  37.  * and made available on an 'AS IS' basis, WITHOUT WARRANTY OF ANY
  38.  * KIND, EITHER EXPRESS OR IMPLIED, AND REALNETWORKS HEREBY DISCLAIMS
  39.  * ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES
  40.  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET
  41.  * ENJOYMENT OR NON-INFRINGEMENT.
  42.  * 
  43.  * Technology Compatibility Kit Test Suite(s) Location:
  44.  *    http://www.helixcommunity.org/content/tck
  45.  * 
  46.  * Contributor(s):
  47.  * 
  48.  * ***** END LICENSE BLOCK ***** */
  49. #include <stdio.h>
  50. #include <stdlib.h>
  51. #include "hlxclib/errno.h"
  52. #include "hlxclib/io.h"
  53. #include "hxtypes.h"
  54. #include "hxstrutl.h"
  55. #include "hxdirlist.h"
  56. #include "windir.h"
  57. #include "hxheap.h"
  58. #ifdef _DEBUG
  59. #undef HX_THIS_FILE
  60. static const char HX_THIS_FILE[] = __FILE__;
  61. #endif
  62. Dir_list*
  63. Dir_list::create(const char* path)
  64. {
  65.     return new Windows_dir_list(path);
  66. }
  67. Windows_dir_list::Windows_dir_list(const char* path) :
  68.     _file_handle(INVALID_HANDLE_VALUE),
  69.     _cur_filename(0),
  70.     _next_error(0),
  71.     _path(new_string(path))
  72. {
  73.     char new_path[_MAX_PATH+10]; /* Flawfinder: ignore */
  74.     SafeSprintf(new_path, _MAX_PATH+10, "%s\*.*", _path);
  75.     
  76.     _file_handle = FindFirstFile(OS_STRING(new_path), &_file_info);
  77.     if (_file_handle == INVALID_HANDLE_VALUE)
  78. _error = EINVAL;
  79. }
  80. Windows_dir_list::~Windows_dir_list()
  81. {
  82.     delete[] _path;
  83.     delete[] _cur_filename;
  84.     if (_file_handle != INVALID_HANDLE_VALUE)
  85. FindClose(_file_handle);
  86. }
  87. const char* Windows_dir_list::get_next()
  88. {
  89.     char*   return_value;
  90.     
  91.     if (_next_error != 0)
  92.     {
  93. _error = _next_error;
  94. return 0;
  95.     }
  96.     delete [] _cur_filename;
  97.     _cur_filename = new_string(OS_STRING(_file_info.cFileName));
  98.     return_value = _cur_filename;
  99.     if (FindNextFile(_file_handle,&_file_info) == 0) 
  100. _next_error = ENOENT;
  101.     return return_value;
  102. }
  103. int
  104. Windows_dir_list::valid_file_name(const char* name)
  105. {
  106.     if ( (strcmp(name, "..") == 0) || (strcmp(name, ".") == 0) )
  107.     {
  108. return 0;
  109.     }
  110.     return 1;
  111. }
  112. int
  113. Windows_dir_list::is_empty()
  114. {
  115.     int isEmpty = 1;
  116.     char new_path[_MAX_PATH+10]; /* Flawfinder: ignore */
  117.     HANDLE f_handle = INVALID_HANDLE_VALUE;
  118.     WIN32_FIND_DATA  f_info;
  119.     SafeSprintf(new_path, _MAX_PATH+10, "%s/*.*", _path);
  120.     f_handle = FindFirstFile(OS_STRING(new_path), &f_info);
  121.     if (f_handle == INVALID_HANDLE_VALUE)
  122.     {
  123. do
  124. {
  125.     if (valid_file_name(OS_STRING(f_info.cFileName)))
  126. isEmpty = 0;
  127. }
  128. while (isEmpty && (FindNextFile(f_handle, &f_info) != 0));
  129.     }
  130.     else
  131. _error = EINVAL;
  132.     FindClose(f_handle);
  133.     return isEmpty;
  134. }