Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
L
lxc
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
lxc
Commits
cb698658
Commit
cb698658
authored
Feb 16, 2009
by
dlezcano
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add missing files to CVS
parent
b2718c72
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
166 additions
and
0 deletions
+166
-0
parse.c
src/lxc/parse.c
+123
-0
parse.h
src/lxc/parse.h
+43
-0
No files found.
src/lxc/parse.c
0 → 100644
View file @
cb698658
/*
* lxc: linux Container library
*
* (C) Copyright IBM Corp. 2007, 2008
*
* Authors:
* Daniel Lezcano <dlezcano at fr.ibm.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <dirent.h>
#include "parse.h"
#include "lxc_log.h"
static
int
dir_filter
(
const
struct
dirent
*
dirent
)
{
if
(
!
strcmp
(
dirent
->
d_name
,
"."
)
||
!
strcmp
(
dirent
->
d_name
,
".."
))
return
0
;
return
1
;
}
int
lxc_dir_for_each
(
const
char
*
name
,
const
char
*
directory
,
lxc_dir_cb
callback
,
void
*
data
)
{
struct
dirent
**
namelist
;
int
n
;
n
=
scandir
(
directory
,
&
namelist
,
dir_filter
,
alphasort
);
if
(
n
<
0
)
{
lxc_log_syserror
(
"failed to scan %s directory"
,
directory
);
return
-
1
;
}
while
(
n
--
)
{
if
(
callback
(
name
,
directory
,
namelist
[
n
]
->
d_name
,
data
))
{
lxc_log_error
(
"callback failed"
);
free
(
namelist
[
n
]);
return
-
1
;
}
free
(
namelist
[
n
]);
}
return
0
;
}
int
lxc_file_for_each_line
(
const
char
*
file
,
lxc_file_cb
callback
,
void
*
buffer
,
size_t
len
,
void
*
data
)
{
FILE
*
f
;
int
err
=
-
1
;
f
=
fopen
(
file
,
"r"
);
if
(
!
f
)
{
lxc_log_syserror
(
"failed to open %s"
,
file
);
return
-
1
;
}
while
(
fgets
(
buffer
,
len
,
f
))
{
err
=
callback
(
buffer
,
data
);
if
(
err
)
goto
out
;
}
out:
fclose
(
f
);
return
err
;
}
int
lxc_char_left_gc
(
char
*
buffer
,
size_t
len
)
{
int
i
;
for
(
i
=
0
;
i
<
len
;
i
++
)
{
if
(
buffer
[
i
]
==
' '
||
buffer
[
i
]
==
'\t'
)
continue
;
return
i
;
}
return
0
;
}
int
lxc_char_right_gc
(
char
*
buffer
,
size_t
len
)
{
int
i
;
for
(
i
=
len
-
1
;
i
>=
0
;
i
--
)
{
if
(
buffer
[
i
]
==
' '
||
buffer
[
i
]
==
'\t'
||
buffer
[
i
]
==
'\n'
||
buffer
[
i
]
==
'\0'
)
continue
;
return
i
+
1
;
}
return
0
;
}
int
lxc_is_line_empty
(
char
*
line
)
{
int
i
;
size_t
len
=
strlen
(
line
);
for
(
i
=
0
;
i
<
len
;
i
++
)
if
(
line
[
i
]
!=
' '
&&
line
[
i
]
!=
'\t'
&&
line
[
i
]
!=
'\n'
&&
line
[
i
]
!=
'\r'
&&
line
[
i
]
!=
'\f'
&&
line
[
i
]
!=
'\0'
)
return
0
;
return
1
;
}
src/lxc/parse.h
0 → 100644
View file @
cb698658
/*
* lxc: linux Container library
*
* (C) Copyright IBM Corp. 2007, 2008
*
* Authors:
* Daniel Lezcano <dlezcano at fr.ibm.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __parse_h
#define __parse_h
typedef
int
(
*
lxc_dir_cb
)(
const
char
*
name
,
const
char
*
directory
,
const
char
*
file
,
void
*
data
);
typedef
int
(
*
lxc_file_cb
)(
void
*
buffer
,
void
*
data
);
extern
int
lxc_dir_for_each
(
const
char
*
name
,
const
char
*
directory
,
lxc_dir_cb
callback
,
void
*
data
);
extern
int
lxc_file_for_each_line
(
const
char
*
file
,
lxc_file_cb
callback
,
void
*
buffer
,
size_t
len
,
void
*
data
);
extern
int
lxc_char_left_gc
(
char
*
buffer
,
size_t
len
);
extern
int
lxc_char_right_gc
(
char
*
buffer
,
size_t
len
);
extern
int
lxc_is_line_empty
(
char
*
line
);
#endif
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment