-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This also fix issue #1003 (missing field pw_gecos in struct passwd) Signed-off-by: Dmitry Moskalchuk <dm@crystax.net>
- Loading branch information
Showing
14 changed files
with
390 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,156 @@ | ||
#!/usr/bin/env ruby | ||
|
||
# Copyright (c) 2011-2015 CrystaX .NET. | ||
# All rights reserved. | ||
# | ||
# Redistribution and use in source and binary forms, with or without modification, are | ||
# permitted provided that the following conditions are met: | ||
# | ||
# 1. Redistributions of source code must retain the above copyright notice, this list of | ||
# conditions and the following disclaimer. | ||
# | ||
# 2. Redistributions in binary form must reproduce the above copyright notice, this list | ||
# of conditions and the following disclaimer in the documentation and/or other materials | ||
# provided with the distribution. | ||
# | ||
# THIS SOFTWARE IS PROVIDED BY CrystaX .NET ''AS IS'' AND ANY EXPRESS OR IMPLIED | ||
# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND | ||
# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CrystaX .NET OR | ||
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON | ||
# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | ||
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
# | ||
# The views and conclusions contained in the software and documentation are those of the | ||
# authors and should not be interpreted as representing official policies, either expressed | ||
# or implied, of CrystaX .NET. | ||
|
||
require 'fileutils' | ||
require 'pathname' | ||
require 'digest' | ||
|
||
MYNAME = Pathname.new(File.expand_path(__FILE__)).relative_path_from(Pathname.new(File.expand_path('../..', __FILE__))).to_s | ||
|
||
TOPDIR = File.realpath(File.join(File.dirname(__FILE__), '..')) | ||
SRCDIR = File.realpath(File.join(TOPDIR, '..', '..', '..', 'system', 'core')) | ||
|
||
PRIVATEDIR = File.join(TOPDIR, 'gen', 'systemcore') | ||
PUBLICDIR = File.join(TOPDIR, 'include') | ||
|
||
ARCHS = [ | ||
"arm", | ||
"x86", | ||
"mips", | ||
"arm64", | ||
"x86_64", | ||
"mips64", | ||
] | ||
|
||
class Generator | ||
def initialize | ||
@files = [] | ||
@fixups = {} | ||
end | ||
|
||
def license | ||
@license = File.read(File.join(TOPDIR, 'LICENSE')).split("\n").map(&:chomp) if @license.nil? | ||
@license | ||
end | ||
private :license | ||
|
||
def relpath(path, from) | ||
Pathname.new(path).relative_path_from(Pathname.new(from)).to_s | ||
end | ||
private :relpath | ||
|
||
def fixup(name, &block) | ||
raise "Fixup '#{name}' already added" if @fixups.has_key?(name.to_s) | ||
raise "No code block given" unless block_given? | ||
@fixups[name.to_s] = lambda { |f| block.call(f) } | ||
end | ||
|
||
def add(f, options = {}) | ||
raise "No such file: #{f}" unless File.exists?(File.join(SRCDIR, f)) | ||
raise "File #{f} already added" if @files.include?(f) | ||
@files << {file: f, options: options} | ||
end | ||
|
||
def generate | ||
total = @files.size | ||
current = 0 | ||
@files.each do |e| | ||
f = e[:file] | ||
options = e[:options] | ||
|
||
src = File.join(SRCDIR, f) | ||
mdst = File.join(options[:public] ? File.join(PUBLICDIR, 'crystax', 'systemcore') : PRIVATEDIR, File.dirname(f), "mangled-#{File.basename(f)}") | ||
|
||
if options[:public] | ||
f = f.split('/')[2..-1].join('/') if f.split('/')[0..1] == ['libc', 'include'] | ||
dst = File.join(PUBLICDIR, f) | ||
else | ||
dst = File.join(PRIVATEDIR, f) | ||
end | ||
|
||
next if File.exists?(dst) && File.exists?(mdst) && | ||
File.mtime(dst) >= File.mtime(mdst) && | ||
File.mtime(mdst) >= File.mtime(src) && | ||
File.mtime(dst) >= File.mtime(__FILE__) && | ||
File.mtime(mdst) >= File.mtime(__FILE__) | ||
|
||
current += 1 | ||
puts "GEN [#{current}/#{total}] #{f}" | ||
|
||
FileUtils.rm_f mdst | ||
FileUtils.mkdir_p File.dirname(mdst) | ||
FileUtils.cp src, mdst | ||
|
||
FileUtils.mkdir_p File.dirname(dst) | ||
File.open(dst, "w") do |df| | ||
df.puts "/* WARNING!!! THIS IS AUTO-GENERATED FILE!!! DO NOT MODIFY IT MANUALLY!!! */" | ||
df.puts "/* GENERATED BY: $CRYSTAX/#{MYNAME} */" | ||
df.puts "" | ||
|
||
df.puts "/*" | ||
license.each do |line| | ||
df.puts " * #{line}".rstrip | ||
end | ||
df.puts " */" | ||
|
||
guard = "__CRYSTAX_INCLUDE_#{Digest::SHA256.new.update(relpath(dst, TOPDIR)).hexdigest}".upcase | ||
df.puts "" | ||
df.puts "#ifndef #{guard}" | ||
df.puts "#define #{guard}" | ||
|
||
fixups = options[:fixup] | ||
fixups = [] if fixups.nil? | ||
fixups = [fixups] unless fixups.is_a?(Array) | ||
df.puts "" unless fixups.empty? | ||
fixups.each do |fxname| | ||
fx = @fixups[fxname.to_s] | ||
raise "No such fixup: '#{fxname}'" if fx.nil? | ||
fx.call(df) | ||
end | ||
|
||
df.puts "" | ||
if options[:public] | ||
df.puts "#include <crystax/id.h>" | ||
df.puts "#include <#{relpath(mdst, File.join(TOPDIR, 'include'))}>" | ||
else | ||
df.puts "#include \"#{File.basename(mdst)}\"" | ||
end | ||
|
||
df.puts "" | ||
df.puts "#endif /* #{guard} */" | ||
end | ||
end | ||
end | ||
end | ||
|
||
g = Generator.new | ||
|
||
g.add "include/private/android_filesystem_config.h" | ||
|
||
g.generate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
* Copyright (c) 2011-2014 CrystaX .NET. | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without modification, are | ||
* permitted provided that the following conditions are met: | ||
* | ||
* 1. Redistributions of source code must retain the above copyright notice, this list of | ||
* conditions and the following disclaimer. | ||
* | ||
* 2. Redistributions in binary form must reproduce the above copyright notice, this list | ||
* of conditions and the following disclaimer in the documentation and/or other materials | ||
* provided with the distribution. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY CrystaX .NET ''AS IS'' AND ANY EXPRESS OR IMPLIED | ||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND | ||
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CrystaX .NET OR | ||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON | ||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | ||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
* | ||
* The views and conclusions contained in the software and documentation are those of the | ||
* authors and should not be interpreted as representing official policies, either expressed | ||
* or implied, of CrystaX .NET. | ||
*/ | ||
|
||
#include <pwd.h> | ||
#include <stdlib.h> | ||
#include <unistd.h> | ||
#include <sys/types.h> | ||
#include <sys/sysconf.h> | ||
|
||
static struct passwd me; | ||
static struct passwd *entries[] = {NULL, NULL}; | ||
static size_t current = 0; | ||
|
||
static void init() | ||
{ | ||
struct passwd *p; | ||
char *buf; | ||
int buflen; | ||
|
||
if (entries[0] != NULL) | ||
return; | ||
|
||
buflen = sysconf(_SC_GETPW_R_SIZE_MAX); | ||
if (buflen <= 0) abort(); | ||
buf = malloc(buflen); | ||
if (!buf) abort(); | ||
|
||
getpwuid_r(getuid(), &me, buf, buflen, &p); | ||
if (!p) abort(); | ||
|
||
entries[0] = &me; | ||
} | ||
|
||
struct passwd *getpwent() | ||
{ | ||
struct passwd *p; | ||
|
||
init(); | ||
|
||
p = entries[current]; | ||
if (current < sizeof(entries)/sizeof(entries[0]) - 1) | ||
++current; | ||
|
||
return p; | ||
} | ||
|
||
void endpwent() | ||
{ | ||
init(); | ||
} | ||
|
||
void setpwent() | ||
{ | ||
init(); | ||
current = 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
SRCFILES := main.c | ||
CFLAGS := -Wall -Wextra -Werror | ||
CFLAGS += -UNDEBUG |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
bin/ | ||
obj/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
include ../common.mk | ||
include $(or $(NDK),../../../..)/tests/onhost.mk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
LOCAL_PATH := $(call my-dir) | ||
include $(LOCAL_PATH)/../common.mk | ||
|
||
include $(CLEAR_VARS) | ||
LOCAL_MODULE := test | ||
LOCAL_SRC_FILES := $(SRCFILES) | ||
LOCAL_CFLAGS := $(CFLAGS) | ||
include $(BUILD_EXECUTABLE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
APP_ABI := all |
Oops, something went wrong.