O'Reilly logo

Effective awk Programming, 4th Edition by Arnold Robbins

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 16. Writing Extensions for gawk

It is possible to add new functions written in C or C++ to gawk using dynamically loaded libraries. This facility is available on systems that support the C dlopen() and dlsym() functions. This chapter describes how to create extensions using code written in C or C++.

If you don’t know anything about C programming, you can safely skip this chapter, although you may wish to review the documentation on the extensions that come with gawk (see The Sample Extensions in the gawk Distribution) and the information on the gawkextlib project (see The gawkextlib Project). The sample extensions are automatically built and installed when gawk is.

Note

When --sandbox is specified, extensions are disabled (see Command-Line Options).

Introduction

An extension (sometimes called a plug-in) is a piece of external compiled code that gawk can load at runtime to provide additional functionality, over and above the built-in capabilities described in the rest of this book.

Extensions are useful because they allow you (of course) to extend gawk’s functionality. For example, they can provide access to system calls (such as chdir() to change directory) and to other C library routines that could be of use. As with most software, “the sky is the limit”; if you can imagine something that you might want to do and can write in C or C++, you can write an extension to do it!

Extensions are written in C or C++, using the application programming interface (API) defined for this purpose ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required