[lxc-devel] [PATCH 04/21] Support both getline and fgetln

Serge Hallyn serge.hallyn at canonical.com
Thu Jan 3 18:26:37 UTC 2013


Quoting Stéphane Graber (stgraber at ubuntu.com):
> Some libc implementations don't have the getline function but instead
> have an equivalent fgetln function.
> 
> Add code to detect both and use whatever is available.
> 
> Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>

Acked-by: Serge E. Hallyn <serge.hallyn at ubuntu.com>

> ---
>  configure.ac     | 3 +++
>  src/lxc/attach.c | 5 +++++
>  src/lxc/parse.c  | 5 +++++
>  3 files changed, 13 insertions(+)
> 
> diff --git a/configure.ac b/configure.ac
> index 9b4c4b2..960d610 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -215,6 +215,9 @@ AC_CHECK_DECLS([PR_CAPBSET_DROP], [], [], [#include <sys/prctl.h>])
>  # Check for optional headers
>  AC_CHECK_HEADERS([sys/signalfd.h])
>  
> +# Check for some functions
> +AC_CHECK_FUNCS([getline fgetln])
> +
>  # Check for some standard binaries
>  AC_PROG_GCC_TRADITIONAL
>  AC_PROG_SED
> diff --git a/src/lxc/attach.c b/src/lxc/attach.c
> index ec0e083..9adb8f9 100644
> --- a/src/lxc/attach.c
> +++ b/src/lxc/attach.c
> @@ -80,7 +80,12 @@ struct lxc_proc_context_info *lxc_proc_get_context_info(pid_t pid)
>  	}
>  
>  	found = 0;
> +
> +	#ifdef HAVE_GETLINE
>  	while (getline(&line, &line_bufsz, proc_file) != -1) {
> +	#else
> +	while ((line = fgetln(proc_file, &line_bufsz))) {
> +	#endif
>  		ret = sscanf(line, "CapBnd: %llx", &info->capability_mask);
>  		if (ret != EOF && ret > 0) {
>  			found = 1;
> diff --git a/src/lxc/parse.c b/src/lxc/parse.c
> index 10510c9..cc6f146 100644
> --- a/src/lxc/parse.c
> +++ b/src/lxc/parse.c
> @@ -29,6 +29,7 @@
>  #include <dirent.h>
>  
>  #include "parse.h"
> +#include "config.h"
>  #include <lxc/log.h>
>  
>  lxc_log_define(lxc_parse, lxc);
> @@ -79,7 +80,11 @@ int lxc_file_for_each_line(const char *file, lxc_file_cb callback, void *data)
>  		return -1;
>  	}
>  
> +	#ifdef HAVE_GETLINE
>  	while (getline(&line, &len, f) != -1) {
> +	#else
> +	while ((line = fgetln(f, &len))) {
> +	#endif
>  		err = callback(line, data);
>  		if (err)
>  			break;
> -- 
> 1.8.0
> 
> 
> ------------------------------------------------------------------------------
> Master Visual Studio, SharePoint, SQL, ASP.NET, C# 2012, HTML5, CSS,
> MVC, Windows 8 Apps, JavaScript and much more. Keep your skills current
> with LearnDevNow - 3,200 step-by-step video tutorials by Microsoft
> MVPs and experts. ON SALE this month only -- learn more at:
> http://p.sf.net/sfu/learnmore_122712
> _______________________________________________
> Lxc-devel mailing list
> Lxc-devel at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/lxc-devel




More information about the lxc-devel mailing list