Export (0) Print
Expand All
Expand Minimize
This topic has not yet been rated - Rate this topic

Chapter 7 Developing Phase: Functions to Change for Interix

Published: May 31, 2006

This chapter describes the important functions not supported in Microsoft® Interix that need to be changed or removed before the code compiles under Interix. This chapter also describes the availability of these functions in the Interix environment and their suitable replacement mechanisms. The functions discussed in the chapter include:

  • Math routines.

  • Regular expressions.

  • System and C library and other platform-specific application programming interfaces (APIs).

The following APIs are not supported by Interix and should not be used:

  • Wide character-type APIs

  • Multibyte character-type APIs (ISO/ANSI C and UNIX 98)

  • Long-long character type (64-bit integer) APIs

  • Message-handling APIs

Using the information in this chapter, you will be able to identify which modifications are required in your application code to ensure compatibility in the Interix environment. You will also be able to use suitable replacement mechanisms in such areas of your application as command line and shell APIs, string-related functions, and system and C library APIs.

Note   Extended UNIX Code (EUC) characters are not supported by Interix and should not be used.

*
On This Page

Math Routines Math Routines
Regular Expressions Regular Expressions
System/C Library and Miscellaneous APIs System/C Library and Miscellaneous APIs

Math Routines

There are two sets of mathematical routines that are not supported by Interix. The first is the IEEE floating-point environment control routines, listed as follows:

  • fpclass

  • fpgetmask

  • fpgetround

  • fpgetsticky

  • fpsetmask

  • fpsetround

  • fpsetsticky

The second set of mathematical routines is the conversion routines, listed as follows:

  • decimal_to_double

  • decimal_to_extended

  • decimal_to_floating

  • decimal_to_quadruple

  • decimal_to_single

  • double_to_decimal

  • econvert

  • extended_to_decimal

  • fconvert

  • file_to_decimal

  • floating_to_decimal

  • func_to_decimal

  • gconvert

  • qeconvert

  • qfconvert

  • qgconvert

  • seconvert

  • quadruple_to_decimal

  • sfconvert

  • sgconvert

  • single_to_decimal

  • string_to_decimal

GMP is a portable library written in C for arbitrary precision arithmetic on integers, rational numbers, and floating-point numbers. You can use this library as the replacement mechanism for the previously described math routines. It aims to provide the fastest possible arithmetic for all applications that need higher precision than is directly supported by the basic C types.

Note   You can download the GMP Library at http://interopsystems.com/InteropToolworks.htm.

Regular Expressions

Interix does not support some of the regular expression function calls. However, Table 7.1 lists functions that can be used to replace them.

Table 7.1. Regular Expression Function Calls Not Supported by Interix

Function Name

Description

Suggested Interix Replacement

re_comp

Compiles and executes a regular expression and returns a character pointer to NULL on success.

int regcomp (regex_t *preg, const char *pattern, int cflags);

int regexec (const regex_t *preg, const char *string, size_t nmatch, regmatch_t pmatch[], int eflags);

re_exec

Compiles and executes a regular expression and returns an integer of 0 or 1 on success.

int regcomp (regex_t *preg, const char *pattern, int cflags);

int regexec (const regex_t *preg, const char *string,       size_t nmatch, regmatch_t pmatch[], int eflags);

Regcmp

Compiles a regular expression and returns a pointer to a compiled form.

int regcomp (regex_t *preg, const char *pattern, int cflags);

regex

Executes a regular expression.

int regexec (const regex_t *preg, const char *string,       size_t nmatch, regmatch_t pmatch[], int eflags);

System/C Library and Miscellaneous APIs

There are many specialized and platform-specific APIs under this category. They are as follows:

  • Command-line and shell APIs

  • String-manipulation functions

  • BSD string and bit functions

  • Time-handling APIs

  • Other system/C library functions

  • Kernel calls

The kernel calls are not supported by Interix and should not be used.

Command-Line and Shell APIs

Interix does not support calls to obtain information about legal user shells from the /etc/shells file, nor does it support the implementation of the popt command-line parser.

To replace the UNIX functions with the Interix functions

  1. Add to the /etc/shells file any additional legal shells that have been ported, such as /bin/bash. The /etc/shells file contains the legal Interix shells /bin/csh, /bin/ksh, /bin/sh, /bin/tcsh.

  2. Write functions named endusershell, getusershell, and setusershell, as listed in Table 7.2.

    Table 7.2. Functions to Implement the Command-Line and Shell APIs in Interix

    Function name

    Description

    Suggested Interix Replacement

    endusershell

    Closes the file of legal user shells (/etc/shells).

    Create endusershell routine to wrap the standard close() file routine. The prototype of the routine is as follows:

    int close (int d)

    getusershell

    Gets legal user shells from /etc/shells.

    Create getusershell routine to wrap the standard read() file routine.

    The prototype of the routine is as follows:

    ssize_t read (int d, void *buf, size_t nbytes)

    popt

    Parses command-line options.

    Use getopt function.

    The prototype of the routine is as follows:

    int getopt (int argc, char * const *argv, const char *optstring)

    setusershell

    Rewinds the file of legal user shells (/etc/shells).

    Create setusershell routine to wrap the standard lseek() file routine to set /etc/shells file back to beginning. The prototype of the routine is as follows:

    off_t lseek (int fd, off_t offset, int whence)

String-Manipulation Functions

Interix supports most of the standard string-handling functions. Interix does not support the atoq, memmem, stpcpy, stpncpy, strfmon, strfry, strnlen, and strtows functions. Use the replacements listed in Table 7.3 for these functions.

Table 7.3. String-Handling Functions Not Supported by Interix

Function name

Description

Suggested Interix Replacement

atoq

Converts string to a long long.

strtoq()

memmem

Finds the start of the first occurrence of a substring in the memory area.

char * strstr (const char *big, const char *little)

stpcpy

Copies the source string, including the terminating \0 character, to the destination.

char * strcpy (char *dst, const char *src)

stpncpy

Copies at most num characters from the source string, including the terminating \0 character, to the destination.

char * strncpy (char *dst, const char *src, size_t len)

strfmon

Formats specified amount according to the format specification and places the result in a character array of size max.

int sprintf (char *str, const char *format ...)

strfry

Randomizes the contents of the string by using rand() to randomly swap characters in the string.

No equivalent in Interix. Customized function can be written using rand().

strnlen

Returns the number of characters in the string, not including the terminating \0 character, but at most maxien.

size_t strlen (const char *s)

BSD String and Bit Functions

String interfaces specified by ANSI/ISO C and found only in the Single UNIX Specification are in string.h. The contents of the strings.h file are listed in Table 7.4.

Table 7.4. String Interfaces in the strings.h File

Function name

Description

bcmp

Compares two strings.

bcopy

Copies at most n characters from src string to dest.

bzero

Places len value of 0 bytes in the string.

ffs

Finds the first bit set (beginning with the least significant bit) and returns the index of that bit.

All the functions mentioned in the preceding table are supported in the Interix environment.

The Interix SDK (software development kit) also supports the BSD 4.4 strsep() and strcasestr() routines.

Time-Handling APIs

The time functions that are not supported by Interix and that cannot be implemented by some other Interix API or set of API calls are adjtime, adjtimex, ntp_adjtime, and tzsetwall.

Note   You can download the rdate tool at
http://www.interopsystems.com/tools/warehouse.htm.

The rdate function sets the date of the system from a remote Network Time Protocol (NTP) server or host.

Other System/C Library Functions

Interix does not support some of the system/C library functions. Table 7.5 lists these functions and their suggested replacements.

Table 7.5. System/C Library Functions Not Supported by Interix

Function Name

Description

Suggested Interix Replacement

on_exit

Registers a function to be called at usual program termination.

int atexit(void (*function)(void))

quotactl

Manipulates disk quotas.

No support or equivalent in Interix.

stime

Sets system time and date.

int settimeofday (struct timeval *tp, void *tzp)

Download

Get the UNIX Custom Application Migration Guide

Update Notifications

Sign up to learn about updates and new releases

Feedback

Send us your comments or suggestions

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.