Problem:
I need to install Primer3, a widely used bio tool that finds allows one to design primers.
Attempts at resolution:
I have attempted to follow their instructions for a Windows installation to no avail as it does not seem provide enough information. I not a experienced programmer by any means. So far I've also referenced this stack overflow post about a similar issue and tried to follow the suggested answer. I also briefly looked at a thread in their github repository, though I can't really understand what they are saying in it. Nothing seems to work so far as the output I get from my command terminal (the mingw32 version) is this:
C:\Users\mqian\Desktop\CGIProject\primer3-2.4.0\primer3-2.4.0\test>mingw32-make
TESTOPTS=--windows
cd ..\src & mingw32-make
mingw32-make[1]: Entering directory 'C:/Users/mqian/Desktop/CGIProject/primer3-2
.4.0/primer3-2.4.0/src'
g++ -c -g -Wall -D__USE_FIXED_PROTOTYPES__ -O2 masker.c
masker.c:8:22: fatal error: sys/mman.h: No such file or directory
compilation terminated.
Makefile:226: recipe for target 'masker.o' failed
mingw32-make[1]: *** [masker.o] Error 1
mingw32-make[1]: Leaving directory 'C:/Users/mqian/Desktop/CGIProject/primer3-2.
4.0/primer3-2.4.0/src'
Makefile:94: recipe for target 'makeexes' failed
mingw32-make: *** [makeexes] Error 2
and if I just try to run a make in the src folder:
C:\Users\mqian\Desktop\CGIProject\primer3-2.4.0\primer3-2.4.0\src>mingw32-make
g++ -c -g -Wall -D__USE_FIXED_PROTOTYPES__ -O2 masker.c
masker.c:8:22: fatal error: sys/mman.h: No such file or directory
compilation terminated.
Makefile:226: recipe for target 'masker.o' failed
mingw32-make: *** [masker.o] Error 1
Is it something that I missing in terms of a software or package needed? Is their makefile bugged? Any help would be appreciated.
P.S. here is a link to their download site on sourceforge. I am using version 2.4.0.
I was able to build it like this on Windows (replace /usr/local with the path where you want to install):
Build mman-win32 from https://github.com/witwall/mman-win32/releases under MSYS2 using:
./configure --prefix=/usr/local --cc=gcc --enable-static --enable-shared &&
make &&
mkdir -p /usr/local/include/mman-win32/sys /usr/local/lib &&
cp -f *.h /usr/local/include/mman-win32/sys/ &&
cp -f *.a /usr/local/lib/ &&
echo Success
Then build primer3 from https://github.com/primer3-org/primer3/releases:
mv src/masker.c src/masker.c.bak
cat > src/masker.c << EOF
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define GETLINE_BUFLEN 128
static ssize_t getline(char** lineptr, size_t* n, FILE* stream)
{
char* bufptr;
char* p;
ssize_t size;
int c;
if (!lineptr || !n || !stream)
return -1;
bufptr = *lineptr;
size = *n;
c = fgetc(stream);
if (c == EOF)
return -1;
if (!bufptr) {
if ((bufptr = (char*)malloc(GETLINE_BUFLEN)) == NULL)
return -1;
size = GETLINE_BUFLEN;
}
p = bufptr;
while (c != EOF) {
if ((p - bufptr) > (size - 1)) {
size = size + GETLINE_BUFLEN;
if ((bufptr = (char*)realloc(bufptr, size)) == NULL)
return -1;
}
*p++ = c;
if (c == '\n') {
break;
}
c = fgetc(stream);
}
*p++ = 0;
*lineptr = bufptr;
*n = size;
return p - bufptr - 1;
}
EOF
cat src/masker.c.bak >> src/masker.c
make -Csrc install PREFIX=/usr/local CC_OPTS="-I/usr/local/include/mman-win32" LDLIBS="-Wl,--as-needed -lmman" &&
echo Success
Related
I've tried adding the following line to the bottom of camera_pipe_generator.cpp to output how Halide compiles into a .html file, but I'm not sure what I'm doing wrong:
processed.compile_to_lowered_stmt("camera_pipe_debugging_trial.html", {}, HTML);
I think my second argument is wrong, but what should I pass in here?
Or is there a different way for me to visualize the schedule? This post seems to suggest a visualizer for Halide exists. Are there any resources available on how to use it?
Thank you!
Edit: I've tried running the command
../../tools/gengen.sh -c c++ -lcurses -l ../../lib/libHalide.a -o tmp/ -e html -s camera_pipe_generator.cpp target=host
However, that resulted in the following error:
Undefined symbols for architecture x86_64:
"_del_curterm", referenced from:
llvm::sys::Process::FileDescriptorHasColors(int) in libHalide.a(llvm_460_Process.cpp.o)
"_set_curterm", referenced from:
llvm::sys::Process::FileDescriptorHasColors(int) in libHalide.a(llvm_460_Process.cpp.o)
"_setupterm", referenced from:
llvm::sys::Process::FileDescriptorHasColors(int) in libHalide.a(llvm_460_Process.cpp.o)
"_tigetnum", referenced from:
llvm::sys::Process::FileDescriptorHasColors(int) in libHalide.a(llvm_460_Process.cpp.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Which I think might be related to running on mac OSX 10.12.3?
Final edit: Added option '-lcurses' to the gengen.sh file and it worked!
To visualize your Halide code to a MPEG file, the following is needed:
Halide filter compiled to AOT binary
Source code to exercise AOT binary
Bash shell script to build and execute HalideTraceViz
All of the above assets in the same folder
Regarding point 4, I'm sure this could altered, but for the trials I had, this was the only way I was able to get things working; anyone who can share their input on that last point is welcome to do so.
1: Halide filter compiled to AOT binary
I used the brighten filter listed on the halide-lang.org tutorial site to create the below listed filter and compile it to a usable binary:
http://halide-lang.org/tutorials/tutorial_lesson_10_aot_compilation_generate.html
#include "Halide.h"
#include <iostream>
namespace
{
auto input = Halide::ImageParam(Halide::type_of< uint8_t >(), 2, std::string{"input_image"});
auto offset = Halide::Param< uint8_t >{"offset"};
} // anonymous namespace
auto create_filter() -> Halide::Func
{
auto x = Halide::Var{"x"};
auto y = Halide::Var{"y"};
auto brighten = Halide::Func{"filter_output"};
brighten(x, y) = input(x, y) + offset;
return brighten;
}
auto schedule_filter(Halide::Func filter_ref) { filter_ref.vectorize(x, 16).parallel(y); }
auto create_aot_binary()
{
auto args = std::vector< Halide::Argument >{input, offset};
brighten.compile_to_file("brighten", args);
}
int main(int argc, const char* argv[])
{
printf("brighten filter AOT binary generator\n");
auto brighten = create_filter();
schedule_filter(brighten);
create_aot_binary();
return 0;
}
2. Source code to exercise AOT binary
#include "brighten.h" // header file created by aot generator in step 1
#include <cassert>
#include <vector>
namespace
{
constexpr auto width = 16 * 4;
constexpr auto height = 16 * 4;
} // anonymous namespace
auto create_input_image() -> std::vector< uint8_t >
{
auto image = std::vector< uint8_t >(width * height, 0);
for (auto y = 0; y < width; y++)
{
for (auto x = 0; x < height; x++)
{
const auto val = x ^ (y + 1);
const auto index = y * height + x;
image[index] = val;
}
}
return image;
}
auto create_buffer_t_with_data(const std::vector< uint8_t >& image) -> buffer_t
{
auto buff = buffer_t{0};
buff.host = image.data();
buff.stride[0] = 1;
buff.stride[1] = width;
buff.extent[0] = width;
buff.extent[1] = height;
buff.elem_size = 1;
}
int main(int argc, const char* argv[])
{
printf("brighten filter exercise\n");
auto input_image = create_input_image();
assert(input_image.size() != 0);
auto input_buf = create_buffer_t_with_data(input_image);
auto output_image = std::vector< uint8_t >(width * height, 0);
assert(output_image.size() != 0);
auto output_buf = create_buffer_t_with_data(output_image);
const auto offset = 1;
auto error = brighten(&input_buf, offset, &output_buf);
(void)error;
return 0;
}
3. Bash shell script to build and execute HalideTraceViz
Now, here is is the bash shell script, where I:
Build the HalideTraceViz.cpp code
Build the AOT generator and filter exerciser app
Copy the binaries into one directory
Call the apps with special parameters that are used for passing data to the HalideTraceViz app
#!/bin/bash
set -e
set -u
function build_binaries()
{
printf "${FUNCNAME[0]}\n"
printf "Building HalideTraceViz\n"
xcodebuild -project visualize_brighten.xcodeproj -scheme HalideTraceViz CONFIGURATION_BUILD_DIR=build/Debug -configuration "Debug" clean build
printf "Building generate_brighten_aot\n"
xcodebuild -project visualize_brighten.xcodeproj -scheme generate_brighten_aot CONFIGURATION_BUILD_DIR=build/Debug -configuration "Debug" clean build
printf "Generating AOT in order to build exercise app\n"
cd build/Debug
HL_TRACE=3 ./generate_brighten_aot
cd $CURRENT_PATH
printf "Building app to exercise brighten filter\n"
xcodebuild -project visualize_brighten.xcodeproj -scheme exercise_brighten_aot CONFIGURATION_BUILD_DIR=build/Debug -configuration "Debug" clean build
cd $CURRENT_PATH
}
function copy_binaries()
{
printf "${FUNCNAME[0]}\n"
if [[ -d $CURRENT_PATH/halide_visualizer ]]; then
rm -Rv $CURRENT_PATH/halide_visualizer
fi
mkdir $CURRENT_PATH/halide_visualizer
cp -Rv $CURRENT_PATH/build/Debug $CURRENT_PATH/halide_visualizer/Debug
}
function visualize_function()
{
printf "${FUNCNAME[0]}\n"
local BLANK=0
local DIMENSIONS=1
local ZOOM=8
local COST=4
local STRIDE0="1 0"
local STRIDE1="0 1"
local FFMPEG_BIN_PATH="YOU_HAVE_TO_DOWNLOAD_THIS_BIN_AND_SET_THE_PATH_HERE"
cd $CURRENT_PATH/halide_visualizer/Debug
echo "About to start visualizing brighten filter"
HL_TRACE=3 ./generate_brighten_aot && \
HL_TRACE_FILE=/dev/stdout ./exercise_brighten_aot | \
$CURRENT_PATH/build/Debug/HalideTraceViz -s 1024 516 -t 1 -d 100 \
-f brighten:input_image 0 255 $BLANK $ZOOM $COST 0 0 $STRIDE0 $STRIDE1 |\
$FFMPEG_BIN_PATH/ffmpeg -r 30 -f rawvideo -pix_fmt bgra -s 1024X516 -i - -y -pix_fmt yuv420p $CURRENT_PATH/movies/brighten_schedule.mp4
cd $CURRENT_PATH
}
main()
{
printf "${FUNCNAME[0]}\n"
CURRENT_PATH=$PWD
build_binaries
copy_binaries
visualize_function
printf "All done\n"
}
printf "Starting ${0##*/}\n"
main
A couple of things to note:
I used Xcode for compiling the projects, but obviously, you can use any tool you are comfortable with
HalideTraceViz comes with it's own cmake file in "Halide/util/"; that folder is part of the Halide git repo
For the bash shell script code, you will have to adjust the folder paths to work with your development setup
All the code that you see listed above was just created now, so I can't guarantee that it works as is :)
Hopefully this helps you get started; if you have any questions, let me know.
toIn the apps/camera_pipe directory, the following command line will generate the HTML stmt file into /tmp/camera_pipe.html:
../../tools/gengen.sh -c c++ -l ../../lib/libHalide.a -o /tmp/ -e html -s camera_pipe_generator.cpp target=host
In searching the site, I found two other similar (at first glance) questions by users 2253605
and 2135159. I also have tried two different versions of gcc. This started out as a hard to
track problem in an application to keep various forms of data in sync on different media. I
eventually boiled it down to a few lines of code that illustrate the problem.
This one is very defined and puzzling. I have not been able to find a case where my system opens
a file, and returns a non-zero file descriptor. It sometimes does really open the specified file
and allows a subsequent read() to occur without error. But by the third open() the
subsequent read() fails, specifying an invalid argument, which can only be a zero value file
descriptor.
The code below tries to open 5 different files, 4 files exist and one that does not exist.
The first 4 opens all return a file descriptor value of zero (stdin).
stdin is not closed, a read() before the first open() or after any one of these open() calls,
will hang until enter is pressed.
Even if stdin were closed, zero should only be returned for the first open(). The
file descriptors are being set and when the open() for the non-existent file is attempted,
it returns an error.
I can't believe that gcc can't open a file. I think I have some kind of O/S-compiler configuration
issue (lib) or maybe I can't see the forest for the trees.
This is on ubuntu 12.04 LTS 64 bit and 64 bit gcc-4.6 also on gcc-4.7 . The flash drive is
formatted ext4. x86_64 intel processor. The installation commands used for gccc-4.7 on 2/10/16
are also shown below. Both gcc-4.6 and gcc-4.7 give identical results. The makefile
is at the end.
Anybody know what's happening here?
The terminal output is shown below the code.
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h
#include <errno.h>
int main()
{
long ret_val;
char cpy_buf[4096];
char s_ary[20][80] =
{
"/media/FLASH16GB_2/Test_dir/t_dir/dm1", //0 exists
"/media/FLASH16GB_2/Test_dir/t_dir/dm2", //1 exists
"/media/FLASH16GB_2/Test_dir/t_dir/dm3", //2 exists
"/media/FLASH16GB_2/Test_dir/t_dir/dm4", //3 exists
"/media/FLASH16GB_2/Test_dir/t_dir/dm5", //4 does not exist
};
char *s1;
long s_fh_1, s_fh_2, s_fh_3, s_fh_4, s_fh_5;
s_fh_1 = 10000;
s1 = &s_ary[0][0];
if (s_fh_1 = open( s1 , O_RDONLY) < 0) // &s_ary[0][0]
{
printf("Error opening source file, name=%s, line# = %i, errno = %i \n",&s_ary[0][0], __LINE__ , errno);
return -1;
}
if (s_fh_2 = open( &s_ary[1][0], O_RDONLY) < 0)
{
printf("Error opening source file, name=%s, line# = %i, errno = %i \n",&s_ary[1][0], __LINE__ , errno);
return -1;
}
if (s_fh_3 = open( &s_ary[2][0], O_RDONLY,0) < 0)
{
printf("Error opening source file, name=%s, line# = %i, errno = %i \n",&s_ary[2][0], __LINE__ , errno);
return -1;
}
if (s_fh_4 = open( &s_ary[3][0], O_RDONLY,0) < 0)
{
printf("Error opening source file, name=%s, line# = %i, errno = %i \n",&s_ary[3][0], __LINE__ , errno);
return -1;
}
printf("s_fh_1 = %li, s_fh_2 = %li, s_fh_3 = %li, s_fh_4 = %li \n", s_fh_1, s_fh_2, s_fh_3, s_fh_4);
if (s_fh_5 = open( &s_ary[4][0], O_RDONLY,0) < 0)
{
printf("Error opening source file, name=%s, line# = %i, errno = %i \n",&s_ary[4][0], __LINE__ , errno);
return -1;
}
return 0;
}
terminal output:
$ make
gcc -g -c -std=iso9899:1999 -o obj/bug_tst_sync_m.o bug_tst_sync_m.c -I../include
gcc -o bug_tst_sync_m obj/bug_tst_sync_m.o -I../include -L /usr/lib64/X11 -lX11 -lm
$ ./bug_tst_sync_m
s_fh_1 = 0, s_fh_2 = 0, s_fh_3 = 0, s_fh_4 = 0
Error opening source file, name=/media/FLASH16GB_2/Test_dir/t_dir/dm5, line# = 88, errno = 2
$
$
gcc-4.7 installation commands used on 2_10_16.
update-alternatives --display gcc
sudo add-apt-repository ppa:ubuntu-toolchain-r/test
sudo apt-get update
sudo apt-get install gcc-4.7
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.7 60
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.6 40
sudo update-alternatives --config gcc
makefile
### where to look for include files ( locally and globally ? -I /usr/include/X11)
IDIR =../include
### compiler to runand generate debugging info (no -g for production release code)
CC=gcc -g
### list of dependencies
CFLAGS=-I$(IDIR)
### where to put object modules
ODIR=obj
### where to look for local library files locally (or write?)
LDIR = -L /usr/lib64/X11 -lX11
### libraries to include m=-lm includes the math libarary, math lib = -lm
LIBS=-lm
### list of all dependency files (.h files)
_DEPS = queues.h InterlockedExchange.h
DEPS = $(patsubst %,$(IDIR)/%,$(_DEPS))
### list of all object files
_OBJ = bug_tst_sync_m.o
OBJ = $(patsubst %,$(ODIR)/%,$(_OBJ))
### compiles object modules and produces debug info
$(ODIR)/%.o: %.c $(DEPS)
$(CC) -c -std=iso9899:1999 -o $# $< $(CFLAGS)
### left side of colon is executable name
### this line links objects and creates the executable
bug_tst_sync_m: $(OBJ)
gcc -o $# $^ $(CFLAGS) $(LDIR) $(LIBS)
### this gets run if you type "make clean". it deletes source backup and object files.
### run this then next make does everything. Without this you get situations that
.PHONY: clean
clean:
rm -f $(ODIR)/*.o *~ core $(INCDIR)/*~
Your problem is operator precedence, < binds harder than =;
if ( s_fh_1 = open(s1 , O_RDONLY) < 0 )
becomes
if ( s_fh_1 = ( open(s1 , O_RDONLY) < 0 ) )
which means, if open returns a number greater than or equal to zero, s_fh_1 will be 0.
I have spent a lot of time researching how to compile a simple PostgreSQL test application written in C and I've got it to compile, run and connect to the PostgreSQL database that comes with Mavericks Server om my Mac Mini running OS X 10.9.3.
Then I decided to try using the Xcode IDE to compile and debug the same PostgreSQL code however, in Xcode I am getting references to Postgres methods listing 7 issues related to "Apple Mach-O Linker (ld) Error", including _PQclear, _PQconnectdb, PQerrorMessage, _PQexec, _PQfinish, _PQprint, _PQstatus. The final error is related to Linker command failed with exit code 1 (use -v to see invocation). Note: I'm not sure where to add the -ld parameters in the Xcode IDE or where to put the -v to find out more.
I have read many of the Stack Overflow items but most of them relate to iOS rather than OSX however I tried to figure out how to use many of those suggestions. Unfortunately I still am not able to figure out where to add the ld (LD) item for postgres similar to what I have in my make file. I tried adding and changing different settings on the Build Phases in the Xcode IDE but I keep getting these 8 issues.
In my code that I'm trying to compile from Xcode I changed one line to point to the location where the libpq-fe.h is as follows but I'm not sure if this is the correct or best approach:
#include </Applications/Server.app/Contents/ServerRoot/usr/include/libpq-fe.h>
Here is my makefile that compiles using make pg_test
## File: makefile
## Rules to create libpq sample application
LDLIBS += -L/Applications/Server.app/Contents/ServerRoot/usr/lib/postgresql9.1/ -lpq
CFLAGS += -c -v -g -I/Applications/Server.app/Contents/ServerRoot/usr/include/
LDFLAGS += -g
pg_test: pg_test.o
Here is my pg_test.c code
// File: pg_test.c
#include <stdlib.h>
#include <libpq-fe.h>
void process_query (PGconn * connection, const char * query_text ) {
PGresult * result;
PQprintOpt options = {0};
if(( result = PQexec ( connection, query_text )) == NULL ) {
printf( "%s\n", PQerrorMessage ( connection ));
return;
}
options.header = 1;
options.align = 1;
options.fieldSep = "|";
PQprint (stdout, result, &options );
PQclear ( result );
}
int main ( ) {
PGconn * connection;
char * dbarg = "user=jerry password=test dbname=jletter hostaddr=127.0.0.1 port=5432";
connection = PQconnectdb(dbarg);
if( PQstatus( connection ) != CONNECTION_OK )
printf( "%s\n", PQerrorMessage( connection ));
else {
process_query( connection, "SELECT * FROM friends" );
}
PQfinish ( connection );
exit (0);
}
Any help would be greatly appreciated.
I have this very simple piece of code that I'm trying to compile. I'm fairly new to GCC from the command line, so please forgive me. I've tried a quite few different things with GCC, but I'm still unable to get it to compile. I do have libusb installed. How can I get this piece of code to compile?
Libusb:
anything:usb mymac$ brew list libusb
/usr/local/Cellar/libusb/1.0.9/include/libusb-1.0/libusb.h
/usr/local/Cellar/libusb/1.0.9/lib/libusb-1.0.0.dylib
/usr/local/Cellar/libusb/1.0.9/lib/pkgconfig/libusb-1.0.pc
/usr/local/Cellar/libusb/1.0.9/lib/ (2 other files)
anything:usb mymac$
GCC attempts (all failed):
gcc -o xout usbtest.c
gcc -o xout usbtest.c -lusb-1.0
gcc -L/usr/local/Cellar/libusb/1.0.9/lib -o xout usbtest.c -lusb-1.0
Error for all attempts:
usbtest.c:3:10: fatal error: 'libusb.h' file not found
#include <libusb.h>
Code:
#include <stdio.h>
#include <stdlib.h>
#include <libusb.h>
int main(int argc, const char * argv[])
{
libusb_device **devs;
libusb_context *context = NULL;
size_t list;
//size_t i;
int ret;
ret = libusb_init(&context);
if(ret < 0)
{
perror("libusb_init");
exit(1);
}
list = libusb_get_device_list(context, &devs);
printf("There are %zd devices found\n", list);
return 0;
}
So I had a similar issue, for some reason gcc doesnt include /usr/local/lib in its default search path on OS X. The quick fix is to add:
-lusb-1.0
to the gcc commands and it should compile.
You are not telling gcc where to look for the header files. This is done by the -I option on the gcc command line for compiling.
e.g.
gcc -I /usr/local/include -o xout usbtest.c
I think Homebrew does provide a symbolic link frominside the Cellar to /usr/local
I'm having a really hard time getting an R library installed that requires some compilation in C. I'm using a Mac OSX Snow Leopard machine and trying to install this R package (here).
I've looked at the thread talking about getline on macs and have tried a few of these fixes, but nothing is working! I'm a newbie and don't know any C, so that may be why! Can anyone give me some tips on how I could modify files in this package to get it to install?? Anyhelp would be pathetically appreciated! Here's the error I'm getting:
** libs
** arch - i386
g++ -arch i386 -I/Library/Frameworks/R.framework/Resources/include -I/Library/Frameworks/R.framework/Resources/include/i386 -I/usr/local/include -D_FASTMAP -DMAQ_LONGREADS -fPIC -g -O2 -c bed2vector.C -o bed2vector.o
In file included from /usr/include/c++/4.2.1/backward/strstream:51,
from bed2vector.C:8:
/usr/include/c++/4.2.1/backward/backward_warning.h:32:2: warning: #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the <X> header for the <X.h> header for C++ includes, or <iostream> instead of the deprecated header <iostream.h>. To disable this warning use -Wno-deprecated.
bed2vector.C: In function ‘int get_a_line(FILE*, BZFILE*, int, std::string&)’:
bed2vector.C:74: error: no matching function for call to ‘getline(char**, size_t*, FILE*&)’
make: *** [bed2vector.o] Error 1
chmod: /Library/Frameworks/R.framework/Resources/library/spp/libs/i386/*: No such file or directory
ERROR: compilation failed for package 'spp'
The easiest solution is probably to add a static definition for getline() to bed2vector.c. This might be good enough:
/* PASTE AT TOP OF FILE */
#include <stdio.h> /* flockfile, getc_unlocked, funlockfile */
#include <stdlib.h> /* malloc, realloc */
#include <errno.h> /* errno */
#include <unistd.h> /* ssize_t */
extern "C" ssize_t getline(char **lineptr, size_t *n, FILE *stream);
/* PASTE REMAINDER AT BOTTOM OF FILE */
ssize_t
getline(char **linep, size_t *np, FILE *stream)
{
char *p = NULL;
size_t i = 0;
if (!linep || !np) {
errno = EINVAL;
return -1;
}
if (!(*linep) || !(*np)) {
*np = 120;
*linep = (char *)malloc(*np);
if (!(*linep)) {
return -1;
}
}
flockfile(stream);
p = *linep;
for (int ch = 0; (ch = getc_unlocked(stream)) != EOF;) {
if (i > *np) {
/* Grow *linep. */
size_t m = *np * 2;
char *s = (char *)realloc(*linep, m);
if (!s) {
int error = errno;
funlockfile(stream);
errno = error;
return -1;
}
*linep = s;
*np = m;
}
p[i] = ch;
if ('\n' == ch) break;
i += 1;
}
funlockfile(stream);
/* Null-terminate the string. */
if (i > *np) {
/* Grow *linep. */
size_t m = *np * 2;
char *s = (char *)realloc(*linep, m);
if (!s) {
return -1;
}
*linep = s;
*np = m;
}
p[i + 1] = '\0';
return ((i > 0)? i : -1);
}
This doesn't handle the case where the line is longer than the maximum value that ssize_t can represent. If you run into that case, you've likely got other problems.
Zeroth question: Have you considered using a package manager like fink or MacPorts rather than compiling yourself? I know that fink has an R package.
First question: How is the R build managed? Is there a ./configure? If so have you looked at the options to it? Does it use make? Scons? Some other dependency manager?
Second question: Have you told the build system that you are working on a Mac? Can you specify that you don't have a libc with native getline?
If the build system doesn't support Mac OS---but I image that R's does---you are probably going to have to download the standalone version, and hack the build to include it. How exactly you do that depends on the build system. And you may need to hack the source some.