foobar2000 SDK  2015-01-14
Functions | Variables
filesystem.cpp File Reference

Go to the source code of this file.

Functions

static void makeBuffer (pfc::array_t< uint8_t > &buffer, size_t size)
 
static void path_pack_string (pfc::string_base &out, const char *src)
 
static int path_unpack_string (pfc::string_base &out, const char *src)
 

Variables

static const char unpack_prefix [] = "unpack://"
 
static const unsigned unpack_prefix_len = 9
 

Function Documentation

static void makeBuffer ( pfc::array_t< uint8_t > &  buffer,
size_t  size 
)
static

Definition at line 40 of file filesystem.cpp.

40  {
41  for(;;) {// Tolerant malloc - allocate a smaller buffer if we're unable to acquire the requested size.
42  try {
43  buffer.set_size_discard( size );
44  return;
45  } catch(std::bad_alloc) {
46  if (size < 256) throw;
47  size >>= 1;
48  }
49  }
50 }
void set_size_discard(t_size p_size)
Definition: array.h:128
static void path_pack_string ( pfc::string_base out,
const char *  src 
)
static

Definition at line 217 of file filesystem.cpp.

218 {
219  out.add_char('|');
220  out << (unsigned) strlen(src);
221  out.add_char('|');
222  out << src;
223  out.add_char('|');
224 }
void add_char(t_uint32 c)
Definition: string_base.cpp:5
static int path_unpack_string ( pfc::string_base out,
const char *  src 
)
static

Definition at line 226 of file filesystem.cpp.

227 {
228  int ptr=0;
229  if (src[ptr++]!='|') return -1;
230  int len = atoi(src+ptr);
231  if (len<=0) return -1;
232  while(src[ptr]!=0 && src[ptr]!='|') ptr++;
233  if (src[ptr]!='|') return -1;
234  ptr++;
235  int start = ptr;
236  while(ptr-start<len)
237  {
238  if (src[ptr]==0) return -1;
239  ptr++;
240  }
241  if (src[ptr]!='|') return -1;
242  out.set_string(&src[start],len);
243  ptr++;
244  return ptr;
245 }
virtual void set_string(const char *p_string, t_size p_length=~0)
Definition: string_base.h:197

Variable Documentation

const char unpack_prefix[] = "unpack://"
static

Definition at line 3 of file filesystem.cpp.

const unsigned unpack_prefix_len = 9
static

Definition at line 4 of file filesystem.cpp.